home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / reload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-05  |  100.5 KB  |  3,276 lines

  1. /* Search an insn for pseudo regs that must be in hard regs and are not.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains subroutines used only from the file reload1.c.
  22.    It knows how to scan one insn for operands and values
  23.    that need to be copied into registers to make valid code.
  24.    It also finds other operands and values which are valid
  25.    but for which equivalent values in registers exist and
  26.    ought to be used instead.
  27.  
  28.    Before processing the first insn of the function, call `init_reload'.
  29.  
  30.    To scan an insn, call `find_reloads'.  This does two things:
  31.    1. sets up tables describing which values must be reloaded
  32.    for this insn, and what kind of hard regs they must be reloaded into;
  33.    2. optionally record the locations where those values appear in
  34.    the data, so they can be replaced properly later.
  35.    This is done only if the second arg to `find_reloads' is nonzero.
  36.  
  37.    The third arg to `find_reloads' specifies the value of `indirect_ok'.
  38.  
  39.    Then you must choose the hard regs to reload those pseudo regs into,
  40.    and generate appropriate load insns before this insn and perhaps
  41.    also store insns after this insn.  Set up the array `reload_reg_rtx'
  42.    to contain the REG rtx's for the registers you used.  In some
  43.    cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
  44.    for certain reloads.  Then that tells you which register to use,
  45.    so you do not need to allocate one.  But you still do need to add extra
  46.    instructions to copy the value into and out of that register.
  47.  
  48.    Finally you must call `subst_reloads' to substitute the reload reg rtx's
  49.    into the locations already recorded.
  50.  
  51. NOTE SIDE EFFECTS:
  52.  
  53.    find_reloads can alter the operands of the instruction it is called on.
  54.  
  55.    1. Two operands of any sort may be interchanged, if they are in a
  56.    commutative instruction.
  57.    This happens only if find_reloads thinks the instruction will compile
  58.    better that way.
  59.  
  60.    2. Pseudo-registers that are equivalent to constants are replaced
  61.    with those constants if they are not in hard registers.
  62.  
  63. 1 happens every time find_reloads is called.
  64. 2 happens only when REPLACE is 1, which is only when
  65. actually doing the reloads, not when just counting them.
  66.  
  67.  
  68. Using a reload register for several reloads in one insn:
  69.  
  70. When an insn has reloads, it is considered as having three parts:
  71. the input reloads, the insn itself after reloading, and the output reloads.
  72. Reloads of values used in memory addresses are often needed for only one part.
  73.  
  74. When this is so, reload_when_needed records which part needs the reload.
  75. Two reloads for different parts of the insn can share the same reload
  76. register.
  77.  
  78. When a reload is used for addresses in multiple parts, or when it is
  79. an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
  80. a register with any other reload.  */
  81.  
  82. #define REG_OK_STRICT
  83.  
  84. #include "config.h"
  85. #include "rtl.h"
  86. #include "insn-config.h"
  87. #include "recog.h"
  88. #include "reload.h"
  89. #include "regs.h"
  90. #include "hard-reg-set.h"
  91. #include "flags.h"
  92. #include "real.h"
  93.  
  94. /* The variables set up by `find_reloads' are:
  95.  
  96.    n_reloads          number of distinct reloads needed; max reload # + 1
  97.        tables indexed by reload number
  98.    reload_in          rtx for value to reload from
  99.    reload_out          rtx for where to store reload-reg afterward if nec
  100.                (often the same as reload_in)
  101.    reload_reg_class      enum reg_class, saying what regs to reload into
  102.    reload_inmode      enum machine_mode; mode this operand should have
  103.                when reloaded, on input.
  104.    reload_outmode      enum machine_mode; mode this operand should have
  105.                when reloaded, on output.
  106.    reload_strict_low      char; 1 if this reload is inside a STRICT_LOW_PART.
  107.    reload_optional      char, nonzero for an optional reload.
  108.                Optional reloads are ignored unless the
  109.                value is already sitting in a register.
  110.    reload_inc          int, positive amount to increment or decrement by if
  111.                reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
  112.                Ignored otherwise (don't assume it is zero).
  113.    reload_in_reg      rtx.  A reg for which reload_in is the equivalent.
  114.                If reload_in is a symbol_ref which came from
  115.                reg_equiv_constant, then this is the pseudo
  116.                which has that symbol_ref as equivalent.
  117.    reload_reg_rtx      rtx.  This is the register to reload into.
  118.                If it is zero when `find_reloads' returns,
  119.                you must find a suitable register in the class
  120.                specified by reload_reg_class, and store here
  121.                an rtx for that register with mode from
  122.                reload_inmode or reload_outmode.
  123.    reload_nocombine      char, nonzero if this reload shouldn't be
  124.                combined with another reload.
  125.    reload_needed_for      rtx, operand this reload is needed for address of.
  126.                0 means it isn't needed for addressing.
  127.    reload_needed_for_multiple
  128.               int, 1 if this reload needed for more than one thing.
  129.    reload_when_needed     enum, classifies reload as needed either for
  130.                addressing an input reload, addressing an output,
  131.                for addressing a non-reloaded mem ref,
  132.                or for unspecified purposes (i.e., more than one
  133.                of the above).  */
  134.  
  135. int n_reloads;
  136.  
  137. rtx reload_in[MAX_RELOADS];
  138. rtx reload_out[MAX_RELOADS];
  139. enum reg_class reload_reg_class[MAX_RELOADS];
  140. enum machine_mode reload_inmode[MAX_RELOADS];
  141. enum machine_mode reload_outmode[MAX_RELOADS];
  142. char reload_strict_low[MAX_RELOADS];
  143. rtx reload_reg_rtx[MAX_RELOADS];
  144. char reload_optional[MAX_RELOADS];
  145. int reload_inc[MAX_RELOADS];
  146. rtx reload_in_reg[MAX_RELOADS];
  147. char reload_nocombine[MAX_RELOADS];
  148. int reload_needed_for_multiple[MAX_RELOADS];
  149. rtx reload_needed_for[MAX_RELOADS];
  150. enum reload_when_needed reload_when_needed[MAX_RELOADS];
  151.  
  152. /* All the "earlyclobber" operands of the current insn
  153.    are recorded here.  */
  154. int n_earlyclobbers;
  155. rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
  156.  
  157. /* Replacing reloads.
  158.  
  159.    If `replace_reloads' is nonzero, then as each reload is recorded
  160.    an entry is made for it in the table `replacements'.
  161.    Then later `subst_reloads' can look through that table and
  162.    perform all the replacements needed.  */
  163.  
  164. /* Nonzero means record the places to replace.  */
  165. static int replace_reloads;
  166.  
  167. /* Each replacement is recorded with a structure like this.  */
  168. struct replacement
  169. {
  170.   rtx *where;            /* Location to store in */
  171.   int what;            /* which reload this is for */
  172.   enum machine_mode mode;    /* mode it must have */
  173. };
  174.  
  175. static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  176.  
  177. /* Number of replacements currently recorded.  */
  178. static int n_replacements;
  179.  
  180. /* MEM-rtx's created for pseudo-regs in stack slots not directly addressable;
  181.    (see reg_equiv_address).  */
  182. static rtx memlocs[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  183. static int n_memlocs;
  184.  
  185. /* The instruction we are doing reloads for;
  186.    so we can test whether a register dies in it.  */
  187. static rtx this_insn;
  188.  
  189. /* Nonzero means (MEM (REG n)) is valid even if (REG n) is spilled.  */
  190. static int indirect_ok;
  191.  
  192. /* If hard_regs_live_known is nonzero,
  193.    we can tell which hard regs are currently live,
  194.    at least enough to succeed in choosing dummy reloads.  */
  195. static int hard_regs_live_known;
  196.  
  197. /* Indexed by hard reg number,
  198.    element is nonegative if hard reg has been spilled.
  199.    This vector is passed to `find_reloads' as an argument
  200.    and is not changed here.  */
  201. static short *static_reload_reg_p;
  202.  
  203. /* Set to 1 in subst_reg_equivs if it changes anything.  */
  204. static int subst_reg_equivs_changed;
  205.  
  206. /* On return from push_reload, holds the reload-number for the OUT
  207.    operand, which can be different for that from the input operand.  */
  208. static int output_reloadnum;
  209.  
  210. static int alternative_allows_memconst ();
  211. static rtx find_dummy_reload ();
  212. static rtx find_reloads_toplev ();
  213. static int find_reloads_address ();
  214. static int find_reloads_address_1 ();
  215. static int hard_reg_set_here_p ();
  216. /* static rtx forget_volatility (); */
  217. static rtx subst_reg_equivs ();
  218. static rtx subst_indexed_address ();
  219. rtx find_equiv_reg ();
  220. static int find_inc_amount ();
  221.  
  222. /* Record one (sometimes two) reload that needs to be performed.
  223.    IN is an rtx saying where the data are to be found before this instruction.
  224.    OUT says where they must be stored after the instruction.
  225.    (IN is zero for data not read, and OUT is zero for data not written.)
  226.    INLOC and OUTLOC point to the places in the instructions where
  227.    IN and OUT were found.
  228.    CLASS is a register class required for the reloaded data.
  229.    INMODE is the machine mode that the instruction requires
  230.    for the reg that replaces IN and OUTMODE is likewise for OUT.
  231.  
  232.    If IN is zero, then OUT's location and mode should be passed as
  233.    INLOC and INMODE.
  234.  
  235.    STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
  236.  
  237.    OPTIONAL nonzero means this reload does not need to be performed:
  238.    it can be discarded if that is more convenient.
  239.  
  240.    The return value is the reload-number for this reload.
  241.  
  242.    If both IN and OUT are nonzero, in some rare cases we might
  243.    want to make two separate reloads.  (Actually we never do this now.)
  244.    Therefore, the reload-number for OUT is stored in
  245.    output_reloadnum when we return; the return value applies to IN.
  246.    Usually (presently always), when IN and OUT are nonzero,
  247.    the two reload-numbers are equal, but the caller should be careful to
  248.    distinguish them.  */
  249.  
  250. static int
  251. push_reload (in, out, inloc, outloc, class,
  252.          inmode, outmode, strict_low, optional, needed_for)
  253.      register rtx in, out;
  254.      rtx *inloc, *outloc;
  255.      enum reg_class class;
  256.      enum machine_mode inmode, outmode;
  257.      int strict_low;
  258.      int optional;
  259.      rtx needed_for;
  260. {
  261.   register int i;
  262.   int dont_share = 0;
  263.  
  264.   /* Compare two RTX's.  */
  265. #define MATCHES(x, y) (x == y || (x != 0 && GET_CODE (x) != REG && rtx_equal_p (x, y)))
  266.  
  267.   /* INMODE and/or OUTMODE could be VOIDmode if no mode
  268.      has been specified for the operand.  In that case,
  269.      use the operand's mode as the mode to reload.  */
  270.   if (inmode == VOIDmode && in != 0)
  271.     inmode = GET_MODE (in);
  272.   if (outmode == VOIDmode && out != 0)
  273.     outmode = GET_MODE (out);
  274.  
  275.   /* If IN is a pseudo register everywhere-equivalent to a constant, and 
  276.      it is not in a hard register, reload straight from the constant,
  277.      since we want to get rid of such pseudo registers.
  278.      Often this is done earlier, but not always in find_reloads_address.  */
  279.   if (in != 0 && GET_CODE (in) == REG)
  280.     {
  281.       register int regno = REGNO (in);
  282.  
  283.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  284.       && reg_equiv_constant[regno] != 0)
  285.     in = reg_equiv_constant[regno];
  286.     }
  287.  
  288.   /* Likewise for OUT.  Of course, OUT will never be equivalent to
  289.      an actual constant, but it might be equivalent to a memory location
  290.      (in the case of a parameter).  */
  291.   if (out != 0 && GET_CODE (out) == REG)
  292.     {
  293.       register int regno = REGNO (out);
  294.  
  295.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  296.       && reg_equiv_constant[regno] != 0)
  297.     out = reg_equiv_constant[regno];
  298.     }
  299.  
  300.   /* If we have a read-write operand with an address side-effect,
  301.      change either IN or OUT so the side-effect happens only once.  */
  302.   if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
  303.     {
  304.       if (GET_CODE (XEXP (in, 0)) == POST_INC
  305.       || GET_CODE (XEXP (in, 0)) == POST_DEC)
  306.     in = gen_rtx (MEM, GET_MODE (in), XEXP (XEXP (in, 0), 0));
  307.       if (GET_CODE (XEXP (in, 0)) == PRE_INC
  308.       || GET_CODE (XEXP (in, 0)) == PRE_DEC)
  309.     out = gen_rtx (MEM, GET_MODE (out), XEXP (XEXP (out, 0), 0));
  310.     }
  311.  
  312.   /* If we are reloading a (SUBREG (MEM ...) ...) or (SUBREG constant ...),
  313.      really reload just the inside expression in its own mode.
  314.      Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
  315.      we can't handle it here because CONST_INT does not indicate a mode.  */
  316.  
  317.   if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) != REG)
  318.     {
  319.       inloc = &SUBREG_REG (in);
  320.       in = *inloc;
  321.       if (GET_CODE (SUBREG_REG (in)) == MEM)
  322.     /* This is supposed to happen only for paradoxical subregs made by
  323.        combine.c.  (SUBREG (MEM)) isn't supposed to occur other ways.  */
  324.     if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
  325.       abort ();
  326.       inmode = GET_MODE (in);
  327.     }
  328.  
  329.   /* If IN appears in OUT, we can't share any input-only reload for IN.  */
  330.   if (in != 0 && out != 0 && reg_overlap_mentioned_p (in, out))
  331.     dont_share = 1;
  332.  
  333.   /* Narrow down the class of register wanted if that is
  334.      desirable on this machine for efficiency.  */
  335.   if (in != 0)
  336.     class = PREFERRED_RELOAD_CLASS (in, class);
  337.  
  338.   if (class == NO_REGS)
  339.     abort ();
  340.  
  341.   /* We can use an existing reload if the class is right
  342.      and at least one of IN and OUT is a match
  343.      and the other is at worst neutral.
  344.      (A zero compared against anything is neutral.)  */
  345.   for (i = 0; i < n_reloads; i++)
  346.     if (reload_reg_class[i] == class
  347.     && reload_strict_low[i] == strict_low
  348.     && ((in != 0 && MATCHES (reload_in[i], in) && ! dont_share
  349.          && (out == 0 || reload_out[i] == 0 || MATCHES (reload_out[i], out)))
  350.         ||
  351.         (out != 0 && MATCHES (reload_out[i], out)
  352.          && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in)))))
  353.       break;
  354.  
  355.   /* Reloading a plain reg for input can match a reload to postincrement
  356.      that reg, since the postincrement's value is the right value.
  357.      Likewise, it can match a preincrement reload, since we regard
  358.      the preincrementation as happening before any ref in this insn
  359.      to that register.  */
  360.   if (i == n_reloads)
  361.     for (i = 0; i < n_reloads; i++)
  362.       if (reload_reg_class[i] == class
  363.       && reload_strict_low[i] == strict_low
  364.       && out == 0 && reload_out[i] == 0
  365.       && ((GET_CODE (in) == REG
  366.            && (GET_CODE (reload_in[i]) == POST_INC
  367.            || GET_CODE (reload_in[i]) == POST_DEC
  368.            || GET_CODE (reload_in[i]) == PRE_INC
  369.            || GET_CODE (reload_in[i]) == PRE_DEC)
  370.            && MATCHES (XEXP (reload_in[i], 0), in))
  371.           ||
  372.           (GET_CODE (reload_in[i]) == REG
  373.            && (GET_CODE (in) == POST_INC
  374.            || GET_CODE (in) == POST_DEC
  375.            || GET_CODE (in) == PRE_INC
  376.            || GET_CODE (in) == PRE_DEC)
  377.            && MATCHES (XEXP (in, 0), reload_in[i]))))
  378.     {
  379.       /* Make sure reload_in ultimately has the increment,
  380.          not the plain register.  */
  381.       if (GET_CODE (in) == REG)
  382.         in = reload_in[i];
  383.       break;
  384.     }
  385.  
  386.   if (i == n_reloads)
  387.     {
  388.       /* We found no existing reload suitable for re-use.
  389.      So add an additional reload.  */
  390.  
  391.       reload_in[i] = in;
  392.       reload_out[i] = out;
  393.       reload_reg_class[i] = class;
  394.       reload_inmode[i] = inmode;
  395.       reload_outmode[i] = outmode;
  396.       reload_reg_rtx[i] = 0;
  397.       reload_optional[i] = optional;
  398.       reload_inc[i] = 0;
  399.       reload_strict_low[i] = strict_low;
  400.       reload_nocombine[i] = 0;
  401.       reload_in_reg[i] = *inloc;
  402.       reload_needed_for[i] = needed_for;
  403.       reload_needed_for_multiple[i] = 0;
  404.  
  405.       n_reloads++;
  406.     }
  407.   else
  408.     {
  409.       /* We are reusing an existing reload,
  410.      but we may have additional information for it.
  411.      For example, we may now have both IN and OUT
  412.      while the old one may have just one of them.  */
  413.  
  414.       if (inmode != VOIDmode)
  415.     reload_inmode[i] = inmode;
  416.       if (outmode != VOIDmode)
  417.     reload_outmode[i] = outmode;
  418.       if (in != 0)
  419.     reload_in[i] = in;
  420.       if (out != 0)
  421.     reload_out[i] = out;
  422.       reload_optional[i] &= optional;
  423.       if (reload_needed_for[i] != needed_for)
  424.     reload_needed_for_multiple[i] = 1;
  425.     }
  426.  
  427.   /* If the ostensible rtx being reload differs from the rtx found
  428.      in the location to substitute, this reload is not safe to combine
  429.      because we cannot reliably tell whether it appears in the insn.  */
  430.  
  431.   if (in != 0 && in != *inloc)
  432.     reload_nocombine[i] = 1;
  433.  
  434. #if 0
  435.   /* This was replaced by changes in find_reloads_address_1 and the new
  436.      function inc_for_reload, which go with a new meaning of reload_inc.  */
  437.  
  438.   /* If this is an IN/OUT reload in an insn that sets the CC,
  439.      it must be for an autoincrement.  It doesn't work to store
  440.      the incremented value after the insn because that would clobber the CC.
  441.      So we must do the increment of the value reloaded from,
  442.      increment it, store it back, then decrement again.  */
  443.   if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
  444.     {
  445.       out = 0;
  446.       reload_out[i] = 0;
  447.       reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
  448.       /* If we did not find a nonzero amount-to-increment-by,
  449.      that contradicts the belief that IN is being incremented
  450.      in an address in this insn.  */
  451.       if (reload_inc[i] == 0)
  452.     abort ();
  453.     }
  454. #endif
  455.  
  456.   /* If we will replace IN and OUT with the reload-reg,
  457.      record where they are located so that substitution need
  458.      not do a tree walk.  */
  459.  
  460.   if (replace_reloads)
  461.     {
  462.       if (inloc != 0)
  463.     {
  464.       register struct replacement *r = &replacements[n_replacements++];
  465.       r->what = i;
  466.       r->where = inloc;
  467.       r->mode = inmode;
  468.     }
  469.       if (outloc != 0 && outloc != inloc)
  470.     {
  471.       register struct replacement *r = &replacements[n_replacements++];
  472.       r->what = i;
  473.       r->where = outloc;
  474.       r->mode = outmode;
  475.     }
  476.     }
  477.  
  478.   /* If this reload is just being introduced and it has both
  479.      an incoming quantity and an outgoing quantity that are
  480.      supposed to be made to match, see if either one of the two
  481.      can serve as the place to reload into.
  482.  
  483.      If one of them is acceptable, set reload_reg_rtx[i]
  484.      to that one.  */
  485.  
  486.   if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
  487.     {
  488.       reload_reg_rtx[i] = find_dummy_reload (in, out, inloc, outloc,
  489.                          reload_reg_class[i], i);
  490.  
  491.       /* If the outgoing register already contains the same value
  492.      as the incoming one, we can dispense with loading it.
  493.      The easiest way to tell the caller that is to give a phony
  494.      value for the incoming operand (same as outgoing one).  */
  495.       if (reload_reg_rtx[i] == out
  496.       && (GET_CODE (in) == REG || CONSTANT_P (in))
  497.       && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
  498.                   static_reload_reg_p, i, inmode))
  499.     reload_in[i] = out;
  500.     }
  501.  
  502.   if (out)
  503.     output_reloadnum = i;
  504.  
  505.   return i;
  506. }
  507.  
  508. /* Record an additional place we must replace a value
  509.    for which we have already recorded a reload.
  510.    RELOADNUM is the value returned by push_reload
  511.    when the reload was recorded.
  512.    This is used in insn patterns that use match_dup.  */
  513.  
  514. static void
  515. push_replacement (loc, reloadnum, mode)
  516.      rtx *loc;
  517.      int reloadnum;
  518.      enum machine_mode mode;
  519. {
  520.   if (replace_reloads)
  521.     {
  522.       register struct replacement *r = &replacements[n_replacements++];
  523.       r->what = reloadnum;
  524.       r->where = loc;
  525.       r->mode = mode;
  526.     }
  527. }
  528.  
  529. /* If there is only one output reload, try to combine it
  530.    with a (logically unrelated) input reload
  531.    to reduce the number of reload registers needed.
  532.  
  533.    This is safe if the input reload does not appear in
  534.    the value being output-reloaded, because this implies
  535.    it is not needed any more once the original insn completes.  */
  536.  
  537. static void
  538. combine_reloads ()
  539. {
  540.   int i;
  541.   int output_reload = -1;
  542.  
  543.   /* Find the output reload; return unless there is exactly one
  544.      and that one is mandatory.  */
  545.  
  546.   for (i = 0; i < n_reloads; i++)
  547.     if (reload_out[i] != 0)
  548.       {
  549.     if (output_reload >= 0)
  550.       return;
  551.     output_reload = i;
  552.       }
  553.  
  554.   if (output_reload < 0 || reload_optional[output_reload])
  555.     return;
  556.  
  557.   /* An input-output reload isn't combinable.  */
  558.  
  559.   if (reload_in[output_reload] != 0)
  560.     return;
  561.  
  562.   /* Check each input reload; can we combine it?  */
  563.  
  564.   for (i = 0; i < n_reloads; i++)
  565.     if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
  566.     /* Life span of this reload must not extend past main insn.  */
  567.     && reload_when_needed[i] != RELOAD_FOR_OUTPUT_RELOAD_ADDRESS
  568.     && reload_inmode[i] == reload_outmode[output_reload]
  569.     && reload_inc[i] == 0
  570.     && reload_reg_rtx[i] == 0
  571.     && reload_strict_low[i] == 0
  572.     && reload_reg_class[i] == reload_reg_class[output_reload]
  573.     && ! reg_overlap_mentioned_p (reload_in[i], reload_out[output_reload]))
  574.       {
  575.     int j;
  576.  
  577.     /* We have found a reload to combine with!  */
  578.     reload_out[i] = reload_out[output_reload];
  579.     reload_outmode[i] = reload_outmode[output_reload];
  580.     /* Mark the old output reload as inoperative.  */
  581.     reload_out[output_reload] = 0;
  582.     /* The combined reload is needed for the entire insn.  */
  583.     reload_needed_for_multiple[i] = 1;
  584.     reload_when_needed[i] = RELOAD_OTHER;
  585.  
  586.     /* Transfer all replacements from the old reload to the combined.  */
  587.     for (j = 0; j < n_replacements; j++)
  588.       if (replacements[j].what == output_reload)
  589.         replacements[j].what = i;
  590.  
  591.     return;
  592.       }
  593. }
  594.  
  595. /* Try to find a reload register for an in-out reload (expressions IN and OUT).
  596.    See if one of IN and OUT is a register that may be used;
  597.    this is desirable since a spill-register won't be needed.
  598.    If so, return the register rtx that proves acceptable.
  599.  
  600.    INLOC and OUTLOC are locations where IN and OUT appear in the insn.
  601.    CLASS is the register class required for the reload.
  602.  
  603.    If FOR_REAL is >= 0, it is the number of the reload,
  604.    and in some cases when it can be discovered that OUT doesn't need
  605.    to be computed, clear out reload_out[FOR_REAL].
  606.  
  607.    If FOR_REAL is -1, this should not be done, because this call
  608.    is just to see if a register can be found, not to find and install it.  */
  609.  
  610. static rtx
  611. find_dummy_reload (in, out, inloc, outloc, class, for_real)
  612.      rtx in, out;
  613.      rtx *inloc, *outloc;
  614.      enum reg_class class;
  615.      int for_real;
  616. {
  617.   rtx value = 0;
  618.   rtx orig_in = in;
  619.  
  620.   while (GET_CODE (out) == SUBREG)
  621.     out = SUBREG_REG (out);
  622.   while (GET_CODE (in) == SUBREG)
  623.     in = SUBREG_REG (in);
  624.  
  625.   /* If operands exceed a word, we can't use either of them
  626.      unless they have the same size.  */
  627.   if (GET_MODE_SIZE (GET_MODE (out)) != GET_MODE_SIZE (GET_MODE (in))
  628.       && (GET_MODE_SIZE (GET_MODE (out)) > UNITS_PER_WORD
  629.       || GET_MODE_SIZE (GET_MODE (in)) > UNITS_PER_WORD))
  630.     return 0;
  631.  
  632.   /* See if OUT will do.  */
  633.   if (GET_CODE (out) == REG)
  634.     {
  635.       register int regno = REGNO (out);
  636.  
  637.       /* When we consider whether the insn uses OUT,
  638.      ignore references within IN.  They don't prevent us
  639.      from copying IN into OUT, because those refs would
  640.      move into the insn that reloads IN.
  641.  
  642.      However, we only ignore IN in its role as this operand.
  643.      If the insn uses IN elsewhere and it contains OUT,
  644.      that counts.  We can't be sure it's the "same" operand
  645.      so it might not go through this reload.  */
  646.       *inloc = const0_rtx;
  647.  
  648.       if (reg_renumber[regno] >= 0)
  649.     regno = reg_renumber[regno];
  650.       if (regno < FIRST_PSEUDO_REGISTER
  651.       /* A fixed reg that can overlap other regs better not be used
  652.          for reloading in any way.  */
  653. #ifdef OVERLAPPING_REGNO_P
  654.       && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
  655. #endif
  656.       && ! refers_to_regno_p (regno, regno + HARD_REGNO_NREGS (regno, GET_MODE (out)),
  657.                   PATTERN (this_insn), outloc)
  658.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  659.     value = out;
  660.  
  661.       *inloc = orig_in;
  662.     }
  663.  
  664.   /* Consider using IN if OUT was not acceptable
  665.      or if OUT dies in this insn (like the quotient in a divmod insn).
  666.      We can't use IN unless it is free after this insn,
  667.      which means we must know accurately which hard regs are live.
  668.      Also, the result can't go in IN if IN is used within OUT.  */
  669.   if (hard_regs_live_known
  670.       && GET_CODE (in) == REG
  671.       && ! find_reg_note (this_insn, REG_UNSET, in)
  672.       && (value == 0
  673.       || find_regno_note (this_insn, REG_DEAD, REGNO (value))))
  674.     {
  675.       register int regno = REGNO (in);
  676.       if (find_regno_note (this_insn, REG_DEAD, regno))
  677.     {
  678.       if (reg_renumber[regno] >= 0)
  679.         regno = reg_renumber[regno];
  680.       if (regno < FIRST_PSEUDO_REGISTER
  681.           && ! refers_to_regno_p (regno,
  682.                       regno + HARD_REGNO_NREGS (regno, GET_MODE (in)),
  683.                       out, 0)
  684.           && ! hard_reg_set_here_p (regno, PATTERN (this_insn))
  685.           && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  686.         {
  687.           /* If we were going to use OUT as the reload reg
  688.          and changed our mind, it means OUT is a dummy that
  689.          dies here.  So don't bother copying value to it.  */
  690.           if (for_real >= 0 && value == out)
  691.         reload_out[for_real] = 0;
  692.           value = in;
  693.         }
  694.     }
  695.     }
  696.  
  697.   return value;
  698. }
  699.  
  700. /* This page contains subroutines used mainly for determining
  701.    whether the IN or an OUT of a reload can serve as the
  702.    reload register.  */
  703.  
  704. /* Return 1 if hard reg number REGNO is stored in by expression X,
  705.    either explicitly or in the guise of a pseudo-reg allocated to REGNO.
  706.    X should be the body of an instruction.  */
  707.  
  708. static int
  709. hard_reg_set_here_p (regno, x)
  710.      register int regno;
  711.      rtx x;
  712. {
  713.   if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
  714.     {
  715.       register rtx op0 = SET_DEST (x);
  716.       while (GET_CODE (op0) == SUBREG)
  717.     op0 = SUBREG_REG (op0);
  718.       if (GET_CODE (op0) == REG)
  719.     {
  720.       register int r = REGNO (op0);
  721.       /* See if this reg includes the specified one.  */
  722.       if (r <= regno && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > regno)
  723.         return 1;
  724.     }
  725.     }
  726.   else if (GET_CODE (x) == PARALLEL)
  727.     {
  728.       register int i = XVECLEN (x, 0) - 1;
  729.       for (; i >= 0; i--)
  730.     if (hard_reg_set_here_p (regno, XVECEXP (x, 0, i)))
  731.       return 1;
  732.     }
  733.  
  734.   return 0;
  735. }
  736.  
  737. /* Return 1 if ADDR is a valid memory address for mode MODE,
  738.    and check that each pseudo reg has the proper kind of
  739.    hard reg.  */
  740.  
  741. int
  742. strict_memory_address_p (mode, addr)
  743.      enum machine_mode mode;
  744.      register rtx addr;
  745. {
  746.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  747.   return 0;
  748.  
  749.  win:
  750.   return 1;
  751. }
  752.  
  753.  
  754. /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
  755.    if they are the same hard reg, and has special hacks for
  756.    autoincrement and autodecrement.
  757.    This is specifically intended for find_reloads to use
  758.    in determining whether two operands match.
  759.    X is the operand whose number is the lower of the two.
  760.  
  761.    The value is 2 if Y contains a pre-increment that matches
  762.    a non-incrementing address in X.  */
  763.  
  764. /* ??? To be completely correct, we should arrange to pass
  765.    for X the output operand and for Y the input operand.
  766.    For now, we assume that the output operand has the lower number
  767.    because that is natural in (SET output (... input ...)).  */
  768.  
  769. int
  770. operands_match_p (x, y)
  771.      register rtx x, y;
  772. {
  773.   register int i;
  774.   register RTX_CODE code = GET_CODE (x);
  775.   register char *fmt;
  776.   int success_2;
  777.       
  778.   if (x == y)
  779.     return 1;
  780.   if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
  781.       && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
  782.                   && GET_CODE (SUBREG_REG (y)) == REG)))
  783.     {
  784.       register int j;
  785.  
  786.       if (code == SUBREG)
  787.     {
  788.       i = REGNO (SUBREG_REG (x));
  789.       if (i >= FIRST_PSEUDO_REGISTER)
  790.         goto slow;
  791.       i += SUBREG_WORD (x);
  792.     }
  793.       else
  794.     i = REGNO (x);
  795.  
  796.       if (GET_CODE (y) == SUBREG)
  797.     {
  798.       j = REGNO (SUBREG_REG (y));
  799.       if (j >= FIRST_PSEUDO_REGISTER)
  800.         goto slow;
  801.       j += SUBREG_WORD (y);
  802.     }
  803.       else
  804.     j = REGNO (y);
  805.  
  806.       return i == j;
  807.     }
  808.   /* If two operands must match, because they are really a single
  809.      operand of an assembler insn, then two postincrements are invalid
  810.      because the assembler insn would increment only once.
  811.      On the other hand, an postincrement matches ordinary indexing
  812.      if the postincrement is the output operand.  */
  813.   if (code == POST_DEC || code == POST_INC)
  814.     return operands_match_p (XEXP (x, 0), y);
  815.   /* Two preincrements are invalid
  816.      because the assembler insn would increment only once.
  817.      On the other hand, an preincrement matches ordinary indexing
  818.      if the preincrement is the input operand.
  819.      In this case, return 2, since some callers need to do special
  820.      things when this happens.  */
  821.   if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
  822.     return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
  823.  
  824.  slow:
  825.  
  826.   /* Now we have disposed of all the cases 
  827.      in which different rtx codes can match.  */
  828.   if (code != GET_CODE (y))
  829.     return 0;
  830.   if (code == LABEL_REF)
  831.     return XEXP (x, 0) == XEXP (y, 0);
  832.   if (code == SYMBOL_REF)
  833.     return XSTR (x, 0) == XSTR (y, 0);
  834.  
  835.   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
  836.  
  837.   if (GET_MODE (x) != GET_MODE (y))
  838.     return 0;
  839.  
  840.   /* Compare the elements.  If any pair of corresponding elements
  841.      fail to match, return 0 for the whole things.  */
  842.  
  843.   success_2 = 0;
  844.   fmt = GET_RTX_FORMAT (code);
  845.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  846.     {
  847.       int val;
  848.       switch (fmt[i])
  849.     {
  850.     case 'i':
  851.       if (XINT (x, i) != XINT (y, i))
  852.         return 0;
  853.       break;
  854.  
  855.     case 'e':
  856.       val = operands_match_p (XEXP (x, i), XEXP (y, i));
  857.       if (val == 0)
  858.         return 0;
  859.       /* If any subexpression returns 2,
  860.          we should return 2 if we are successful.  */
  861.       if (val == 2)
  862.         success_2 = 1;
  863.       break;
  864.  
  865.     case '0':
  866.       break;
  867.  
  868.       /* It is believed that rtx's at this level will never
  869.          contain anything but integers and other rtx's,
  870.          except for within LABEL_REFs and SYMBOL_REFs.  */
  871.     default:
  872.       abort ();
  873.     }
  874.     }
  875.   return 1 + success_2;
  876. }
  877.  
  878. /* Return the number of times character C occurs in string S.  */
  879.  
  880. static int
  881. n_occurrences (c, s)
  882.      char c;
  883.      char *s;
  884. {
  885.   int n = 0;
  886.   while (*s)
  887.     n += (*s++ == c);
  888.   return n;
  889. }
  890.  
  891. struct decomposition
  892. {
  893.   int reg_flag;
  894.   int safe;
  895.   rtx base;
  896.   int start;
  897.   int end;
  898. };
  899.  
  900. /* Describe the range of registers or memory referenced by X.
  901.    If X is a register, set REG_FLAG and put the first register 
  902.    number into START and the last plus one into END.
  903.    If X is a memory reference, put a base address into BASE 
  904.    and a range of integer offsets into START and END.
  905.    If X is pushing on the stack, we can assume it causes no trouble, 
  906.    so we set the SAFE field.  */
  907.  
  908. static struct decomposition
  909. decompose (x)
  910.      rtx x;
  911. {
  912.   struct decomposition val;
  913.   int all_const = 0;
  914.  
  915.   val.reg_flag = 0;
  916.   val.safe = 0;
  917.   if (GET_CODE (x) == MEM)
  918.     {
  919.       rtx base, offset = 0;
  920.       rtx addr = XEXP (x, 0);
  921.  
  922.       if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
  923.       || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
  924.     {
  925.       val.base = XEXP (addr, 0);
  926.       val.start = - GET_MODE_SIZE (GET_MODE (x));
  927.       val.end = GET_MODE_SIZE (GET_MODE (x));
  928.       val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
  929.       return val;
  930.     }
  931.  
  932.       if (GET_CODE (addr) == CONST)
  933.     {
  934.       addr = XEXP (addr, 0);
  935.       all_const = 1;
  936.     }
  937.       if (GET_CODE (addr) == PLUS)
  938.     {
  939.       if (CONSTANT_P (XEXP (addr, 0)))
  940.         {
  941.           base = XEXP (addr, 1);
  942.           offset = XEXP (addr, 0);
  943.         }
  944.       else if (CONSTANT_P (XEXP (addr, 1)))
  945.         {
  946.           base = XEXP (addr, 0);
  947.           offset = XEXP (addr, 1);
  948.         }
  949.     }
  950.  
  951.       if (offset == 0)
  952.     {
  953.       base = addr;
  954.       offset = const0_rtx;
  955.     } 
  956.       if (GET_CODE (offset) == CONST)
  957.     offset = XEXP (offset, 0);
  958.       if (GET_CODE (offset) == PLUS)
  959.     {
  960.       if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
  961.         {
  962.           base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
  963.           offset = XEXP (offset, 0);
  964.         }
  965.       else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
  966.         {
  967.           base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
  968.           offset = XEXP (offset, 1);
  969.         }
  970.       else
  971.         {
  972.           base = gen_rtx (PLUS, GET_MODE (base), base, offset);
  973.           offset = const0_rtx;
  974.         }
  975.     }
  976.       else if (GET_CODE (offset) != CONST_INT)
  977.     {
  978.       base = gen_rtx (PLUS, GET_MODE (base), base, offset);
  979.       offset = const0_rtx;
  980.     }
  981.  
  982.       if (all_const && GET_CODE (base) == PLUS)
  983.     base = gen_rtx (CONST, GET_MODE (base), base);
  984.  
  985.       if (GET_CODE (offset) != CONST_INT)
  986.     abort ();
  987.  
  988.       val.start = INTVAL (offset);
  989.       val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
  990.       val.base = base;
  991.       return val;
  992.     }
  993.   else if (GET_CODE (x) == REG)
  994.     {
  995.       val.reg_flag = 1;
  996.       val.start = true_regnum (x); 
  997.       if (val.start < 0)
  998.     {
  999.       /* A pseudo with no hard reg.  */
  1000.       val.start = REGNO (x);
  1001.       val.end = val.start + 1;
  1002.     }
  1003.       else
  1004.     /* A hard reg.  */
  1005.     val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
  1006.     }
  1007.   else if (GET_CODE (x) == SUBREG)
  1008.     {
  1009.       if (GET_CODE (SUBREG_REG (x)) != REG)
  1010.     /* This could be more precise, but it's good enough.  */
  1011.     return decompose (SUBREG_REG (x));
  1012.       val.reg_flag = 1;
  1013.       val.start = true_regnum (x); 
  1014.       if (val.start < 0)
  1015.     return decompose (SUBREG_REG (x));
  1016.       else
  1017.     /* A hard reg.  */
  1018.     val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
  1019.     }
  1020.   else
  1021.     abort ();
  1022.   return val;
  1023. }
  1024.  
  1025. /* Return 1 if altering Y will not modify the value of X.
  1026.    Y is also described by YDATA, which should be decompose (Y).  */
  1027.  
  1028. static int
  1029. immune_p (x, y, ydata)
  1030.      rtx x, y;
  1031.      struct decomposition ydata;
  1032. {
  1033.   struct decomposition xdata;
  1034.  
  1035.   if (ydata.reg_flag)
  1036.     return !refers_to_regno_p (ydata.start, ydata.end, x, 0);
  1037.   if (ydata.safe)
  1038.     return 1;
  1039.  
  1040.   if (GET_CODE (y) != MEM)
  1041.     abort ();
  1042.   /* If Y is memory and X is not, Y can't affect X.  */
  1043.   if (GET_CODE (x) != MEM)
  1044.     return 1;
  1045.  
  1046.   xdata =  decompose (x);
  1047.  
  1048.   if (! rtx_equal_p (xdata.base, ydata.base))
  1049.     {
  1050.       /* If bases are distinct symbolic constants, there is no overlap.  */
  1051.       if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
  1052.     return 1;
  1053.       /* Constants and stack slots never overlap.  */
  1054.       if (CONSTANT_P (xdata.base)
  1055.       && (ydata.base == frame_pointer_rtx
  1056.           || ydata.base == stack_pointer_rtx))
  1057.     return 1;
  1058.       if (CONSTANT_P (ydata.base)
  1059.       && (xdata.base == frame_pointer_rtx
  1060.           || xdata.base == stack_pointer_rtx))
  1061.     return 1;
  1062.       /* If either base is variable, we don't know anything.  */
  1063.       return 0;
  1064.     }
  1065.  
  1066.  
  1067.   return (xdata.start >= ydata.end || ydata.start >= xdata.end);
  1068. }
  1069.  
  1070. /* Main entry point of this file: search the body of INSN
  1071.    for values that need reloading and record them with push_reload.
  1072.    REPLACE nonzero means record also where the values occur
  1073.    so that subst_reloads can be used.
  1074.    IND_OK says that a memory reference is a valid memory address.
  1075.  
  1076.    LIVE_KNOWN says we have valid information about which hard
  1077.    regs are live at each point in the program; this is true when
  1078.    we are called from global_alloc but false when stupid register
  1079.    allocation has been done.
  1080.  
  1081.    RELOAD_REG_P if nonzero is a vector indexed by hard reg number
  1082.    which is nonnegative if the reg has been commandeered for reloading into.
  1083.    It is copied into STATIC_RELOAD_REG_P and referenced from there
  1084.    by various subroutines.  */
  1085.  
  1086. void
  1087. find_reloads (insn, replace, ind_ok, live_known, reload_reg_p)
  1088.      rtx insn;
  1089.      int replace, ind_ok;
  1090.      int live_known;
  1091.      short *reload_reg_p;
  1092. {
  1093. #ifdef REGISTER_CONSTRAINTS
  1094.  
  1095.   enum reload_modified { RELOAD_NOTHING, RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE };
  1096.  
  1097.   register int insn_code_number;
  1098.   register int i;
  1099.   int noperands;
  1100.   /* These are the constraints for the insn.  We don't change them.  */
  1101.   char *constraints1[MAX_RECOG_OPERANDS];
  1102.   /* These start out as the constraints for the insn
  1103.      and they are chewed up as we consider alternatives.  */
  1104.   char *constraints[MAX_RECOG_OPERANDS];
  1105.   /* Nonzero for a MEM operand whose entire address needs a reload.  */
  1106.   int address_reloaded[MAX_RECOG_OPERANDS];
  1107.   int n_alternatives;
  1108.   int this_alternative[MAX_RECOG_OPERANDS];
  1109.   char this_alternative_win[MAX_RECOG_OPERANDS];
  1110.   char this_alternative_offmemok[MAX_RECOG_OPERANDS];
  1111.   char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
  1112.   int this_alternative_matches[MAX_RECOG_OPERANDS];
  1113.   int swapped;
  1114.   int goal_alternative[MAX_RECOG_OPERANDS];
  1115.   int this_alternative_number;
  1116.   int goal_alternative_number;
  1117.   int operand_reloadnum[MAX_RECOG_OPERANDS];
  1118.   int goal_alternative_matches[MAX_RECOG_OPERANDS];
  1119.   int goal_alternative_matched[MAX_RECOG_OPERANDS];
  1120.   char goal_alternative_win[MAX_RECOG_OPERANDS];
  1121.   char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
  1122.   char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
  1123.   int goal_alternative_swapped;
  1124.   enum reload_modified modified[MAX_RECOG_OPERANDS];
  1125.   int best;
  1126.   int commutative;
  1127.   char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
  1128.   rtx substed_operand[MAX_RECOG_OPERANDS];
  1129.   rtx body = PATTERN (insn);
  1130.   int goal_earlyclobber, this_earlyclobber;
  1131.   enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
  1132.  
  1133.   this_insn = insn;
  1134.   n_reloads = 0;
  1135.   n_replacements = 0;
  1136.   n_memlocs = 0;
  1137.   n_earlyclobbers = 0;
  1138.   replace_reloads = replace;
  1139.   indirect_ok = ind_ok;
  1140.   hard_regs_live_known = live_known;
  1141.   static_reload_reg_p = reload_reg_p;
  1142.  
  1143.   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
  1144.      Make OPERANDS point to a vector of operand values.
  1145.      Make OPERAND_LOCS point to a vector of pointers to
  1146.      where the operands were found.
  1147.      Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
  1148.      constraint-strings for this insn.
  1149.      Return if the insn needs no reload processing.  */
  1150.  
  1151.   switch (GET_CODE (body))
  1152.     {
  1153.     case USE:
  1154.     case CLOBBER:
  1155.     case ASM_INPUT:
  1156.     case ADDR_VEC:
  1157.     case ADDR_DIFF_VEC:
  1158.       return;
  1159.  
  1160.     case SET:
  1161.       /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs.  */
  1162.       if (GET_CODE (SET_DEST (body)) == REG
  1163.       && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
  1164.       && GET_CODE (SET_SRC (body)) == REG
  1165.       && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER)
  1166.     return;
  1167.     case PARALLEL:
  1168.     case ASM_OPERANDS:
  1169.       noperands = asm_noperands (body);
  1170.       if (noperands >= 0)
  1171.     {
  1172.       /* This insn is an `asm' with operands.  */
  1173.  
  1174.       insn_code_number = -1;
  1175.  
  1176.       /* expand_asm_operands makes sure there aren't too many operands.  */
  1177.       if (noperands > MAX_RECOG_OPERANDS)
  1178.         abort ();
  1179.  
  1180.       /* Now get the operand values and constraints out of the insn.  */
  1181.  
  1182.       decode_asm_operands (body, recog_operand, recog_operand_loc,
  1183.                    constraints, operand_mode);
  1184.       if (noperands > 0)
  1185.         {
  1186.           bcopy (constraints, constraints1, noperands * sizeof (char *));
  1187.           n_alternatives = n_occurrences (',', constraints[0]) + 1;
  1188.           for (i = 1; i < noperands; i++)
  1189.         if (n_alternatives != n_occurrences (',', constraints[0]) + 1)
  1190.           {
  1191.             error_for_asm (insn, "operand constraints differ in number of alternatives");
  1192.             /* Avoid further trouble with this insn.  */
  1193.             PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
  1194.             n_reloads = 0;
  1195.             return;
  1196.           }
  1197.         }
  1198.       break;
  1199.     }
  1200.  
  1201.     default:
  1202.       /* Ordinary insn: recognize it, allocate space for operands and
  1203.      constraints, and get them out via insn_extract.  */
  1204.  
  1205.       insn_code_number = recog_memoized (insn);
  1206.       noperands = insn_n_operands[insn_code_number];
  1207.       n_alternatives = insn_n_alternatives[insn_code_number];
  1208.       /* Just return "no reloads" if insn has no operands with constraints.  */
  1209.       if (n_alternatives == 0)
  1210.     return;
  1211.       insn_extract (insn);
  1212.       for (i = 0; i < noperands; i++)
  1213.     {
  1214.       constraints[i] = constraints1[i]
  1215.         = insn_operand_constraint[insn_code_number][i];
  1216.       operand_mode[i] = insn_operand_mode[insn_code_number][i];
  1217.     }
  1218.     }
  1219.  
  1220.   if (noperands == 0)
  1221.     return;
  1222.  
  1223.   commutative = -1;
  1224.  
  1225.   /* If we will need to know, later, whether some pair of operands
  1226.      are the same, we must compare them now and save the result.
  1227.      Reloading the base and index registers will clobber them
  1228.      and afterward they will fail to match.  */
  1229.  
  1230.   for (i = 0; i < noperands; i++)
  1231.     {
  1232.       register char *p;
  1233.       register int c;
  1234.  
  1235.       substed_operand[i] = recog_operand[i];
  1236.       p = constraints[i];
  1237.  
  1238.       /* Scan this operand's constraint to see if it should match another.  */
  1239.  
  1240.       while (c = *p++)
  1241.     if (c == '%')
  1242.       commutative = i;
  1243.     else if (c >= '0' && c <= '9')
  1244.       {
  1245.         c -= '0';
  1246.         operands_match[c][i]
  1247.           = operands_match_p (recog_operand[c], recog_operand[i]);
  1248.         /* If C can be commuted with C+1, and C might need to match I,
  1249.            then C+1 might also need to match I.  */
  1250.         if (commutative >= 0)
  1251.           {
  1252.         if (c == commutative || c == commutative + 1)
  1253.           {
  1254.             int other = c + (c == commutative ? 1 : -1);
  1255.             operands_match[other][i]
  1256.               = operands_match_p (recog_operand[other], recog_operand[i]);
  1257.           }
  1258.         if (i == commutative || i == commutative + 1)
  1259.           {
  1260.             int other = i + (i == commutative ? 1 : -1);
  1261.             operands_match[c][other]
  1262.             = operands_match_p (recog_operand[c], recog_operand[other]);
  1263.           }
  1264.         /* Note that C is supposed to be less than I.
  1265.            No need to consider altering both C and I
  1266.            because in that case we would alter one into the other.  */
  1267.           }
  1268.       }
  1269.     }
  1270.  
  1271.   /* Examine each operand that is a memory reference or memory address
  1272.      and reload parts of the addresses into index registers.
  1273.      While we are at it, initialize the array `modified'.
  1274.      Also here any references to pseudo regs that didn't get hard regs
  1275.      but are equivalent to constants get replaced in the insn itself
  1276.      with those constants.  Nobody will ever see them again.  */
  1277.  
  1278.   for (i = 0; i < noperands; i++)
  1279.     {
  1280.       register RTX_CODE code = GET_CODE (recog_operand[i]);
  1281.       modified[i] = RELOAD_READ;
  1282.       address_reloaded[i] = 0;
  1283.       if (constraints[i][0] == 'p')
  1284.     {
  1285.       find_reloads_address (VOIDmode, 0,
  1286.                 recog_operand[i], recog_operand_loc[i],
  1287.                 recog_operand[i]);
  1288.       substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1289.     }
  1290.       else if (code == MEM)
  1291.     {
  1292.       if (find_reloads_address (GET_MODE (recog_operand[i]),
  1293.                     recog_operand_loc[i],
  1294.                     XEXP (recog_operand[i], 0),
  1295.                     &XEXP (recog_operand[i], 0),
  1296.                     recog_operand[i]))
  1297.         address_reloaded[i] = 1;
  1298.       substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1299.     }
  1300.       else if (code == SUBREG)
  1301.     substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
  1302.       = find_reloads_toplev (recog_operand[i]);
  1303.       else if (code == REG)
  1304.     {
  1305.       /* This is equivalent to calling find_reloads_toplev.
  1306.          The code is duplicated for speed.  */
  1307.       register int regno = REGNO (recog_operand[i]);
  1308.       if (reg_equiv_constant[regno] != 0)
  1309.         substed_operand[i] = recog_operand[i]
  1310.           = reg_equiv_constant[regno];
  1311. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  1312.      that feeds this insn.  */
  1313.       if (reg_equiv_mem[regno] != 0)
  1314.         substed_operand[i] = recog_operand[i]
  1315.           = reg_equiv_mem[regno];
  1316. #endif
  1317.       if (reg_equiv_address[regno] != 0)
  1318.         {
  1319.           *recog_operand_loc[i] = recog_operand[i]
  1320.         = gen_rtx (MEM, GET_MODE (recog_operand[i]),
  1321.                reg_equiv_address[regno]);
  1322.           find_reloads_address (GET_MODE (recog_operand[i]),
  1323.                     recog_operand_loc[i],
  1324.                     XEXP (recog_operand[i], 0),
  1325.                     &XEXP (recog_operand[i], 0),
  1326.                     recog_operand[i]);
  1327.           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1328.         }
  1329.     }
  1330.     }
  1331.  
  1332.   /* Now see what we need for pseudo-regs that didn't get hard regs
  1333.      or got the wrong kind of hard reg.  For this, we must consider
  1334.      all the operands together against the register constraints.  */
  1335.  
  1336.   best = MAX_RECOG_OPERANDS + 100;
  1337.  
  1338.   swapped = 0;
  1339.  try_swapped:
  1340.  
  1341.   /* The constraints are made of several alternatives.
  1342.      Each operand's constraint looks like foo,bar,... with commas
  1343.      separating the alternatives.  The first alternatives for all
  1344.      operands go together, the second alternatives go together, etc.
  1345.  
  1346.      First loop over alternatives.  */
  1347.  
  1348.   for (this_alternative_number = 0;
  1349.        this_alternative_number < n_alternatives;
  1350.        this_alternative_number++)
  1351.     {
  1352.       /* Loop over operands for one constraint alternative.  */
  1353.       /* LOSERS counts those that don't fit this alternative
  1354.      and would require loading.  */
  1355.       int losers = 0;
  1356.       /* BAD is set to 1 if it some operand can't fit this alternative
  1357.      even after reloading.  */
  1358.       int bad = 0;
  1359.       /* REJECT is a count of how undesirable this alternative says it is
  1360.      if any reloading is required.  If the alternative matches exactly
  1361.      then REJECT is ignored, but otherwise it gets this much
  1362.      counted against it in addition to the reloading needed.  */
  1363.       int reject = 0;
  1364.  
  1365.       this_earlyclobber = 0;
  1366.  
  1367.       for (i = 0; i < noperands; i++)
  1368.     {
  1369.       register char *p = constraints[i];
  1370.       register int win = 0;
  1371.       /* 0 => this operand can be reloaded somehow for this alternative */
  1372.       int badop = 1;
  1373.       /* 0 => this operand can be reloaded if the alternative allows regs.  */
  1374.       int winreg = 0;
  1375.       int c;
  1376.       register rtx operand = recog_operand[i];
  1377.       int offset = 0;
  1378.       /* Nonzero means this is a MEM that must be reloaded into a reg
  1379.          regardless of what the constraint says.  */
  1380.       int force_reload = 0;
  1381.       int offmemok = 0;
  1382.       int earlyclobber = 0;
  1383.  
  1384.       /* If the operand is a SUBREG, extract
  1385.          the REG or MEM (or maybe even a constant) within.
  1386.          (Constants can occur as a result of reg_equiv_constant.)  */
  1387.  
  1388.       while (GET_CODE (operand) == SUBREG)
  1389.         {
  1390.           offset += SUBREG_WORD (operand);
  1391.           operand = SUBREG_REG (operand);
  1392.           if (GET_CODE (operand) != REG)
  1393.         force_reload = 1;
  1394.         }
  1395.  
  1396.       this_alternative[i] = (int) NO_REGS;
  1397.       this_alternative_win[i] = 0;
  1398.       this_alternative_offmemok[i] = 0;
  1399.       this_alternative_earlyclobber[i] = 0;
  1400.       this_alternative_matches[i] = -1;
  1401.  
  1402.       /* An empty constraint or empty alternative
  1403.          allows anything which matched the pattern.  */
  1404.       if (*p == 0 || *p == ',')
  1405.         win = 1, badop = 0;
  1406.  
  1407.       /* Scan this alternative's specs for this operand;
  1408.          set WIN if the operand fits any letter in this alternative.
  1409.          Otherwise, clear BADOP if this operand could
  1410.          fit some letter after reloads,
  1411.          or set WINREG if this operand could fit after reloads
  1412.          provided the constraint allows some registers.  */
  1413.  
  1414.       while (*p && (c = *p++) != ',')
  1415.         switch (c)
  1416.           {
  1417.           case '=':
  1418.         modified[i] = RELOAD_WRITE;
  1419.         break;
  1420.  
  1421.           case '+':
  1422.         modified[i] = RELOAD_READ_WRITE;
  1423.         break;
  1424.  
  1425.           case '*':
  1426.         break;
  1427.  
  1428.           case '%':
  1429.         commutative = i;
  1430.         break;
  1431.  
  1432.           case '?':
  1433.         reject++;
  1434.         break;
  1435.  
  1436.           case '!':
  1437.         reject = 100;
  1438.         break;
  1439.  
  1440.           case '#':
  1441.         /* Ignore rest of this alternative as far as
  1442.            reloading is concerned.  */
  1443.         while (*p && *p != ',') p++;
  1444.         break;
  1445.  
  1446.           case '0':
  1447.           case '1':
  1448.           case '2':
  1449.           case '3':
  1450.           case '4':
  1451.         c -= '0';
  1452.         this_alternative_matches[i] = c;
  1453.         /* We are supposed to match a previous operand.
  1454.            If we do, we win if that one did.
  1455.            If we do not, count both of the operands as losers.
  1456.            (This is too conservative, since most of the time
  1457.            only a single reload insn will be needed to make
  1458.            the two operands win.  As a result, this alternative
  1459.            may be rejected when it is actually desirable.)  */
  1460.         if ((swapped && (c != commutative || i != commutative + 1))
  1461.             /* If we are matching as if two operands were swapped,
  1462.                also pretend that operands_match had been computed
  1463.                with swapped.
  1464.                But if I is the second of those and C is the first,
  1465.                don't exchange them, because operands_match is valid
  1466.                only on one side of its diagonal.  */
  1467.             ? (operands_match
  1468.                 [(c == commutative || c == commutative + 1)
  1469.              ? 2*commutative + 1 - c : c]
  1470.                 [(i == commutative || i == commutative + 1)
  1471.              ? 2*commutative + 1 - i : i])
  1472.             : operands_match[c][i])
  1473.           win = this_alternative_win[c];
  1474.         else
  1475.           {
  1476.             /* Operands don't match.  */
  1477.             rtx value;
  1478.             /* Retroactively mark the operand we had to match
  1479.                as a loser, if it wasn't already.  */
  1480.             if (this_alternative_win[c])
  1481.               losers++;
  1482.             this_alternative_win[c] = 0;
  1483.             if (this_alternative[c] == (int) NO_REGS)
  1484.               bad = 1;
  1485.             /* But count the pair only once in the total badness of
  1486.                this alternative, if the pair can be a dummy reload.  */
  1487.             value
  1488.               = find_dummy_reload (recog_operand[i], recog_operand[c],
  1489.                        recog_operand_loc[i], recog_operand_loc[c],
  1490.                        this_alternative[c], -1);
  1491.  
  1492.             if (value != 0)
  1493.               losers--;
  1494.           }
  1495.         /* This can be fixed with reloads if the operand
  1496.            we are supposed to match can be fixed with reloads.  */
  1497.         badop = 0;
  1498.         this_alternative[i] = this_alternative[c];
  1499.         break;
  1500.  
  1501.           case 'p':
  1502.         /* All necessary reloads for an address_operand
  1503.            were handled in find_reloads_address.  */
  1504.         this_alternative[i] = (int) ALL_REGS;
  1505.         win = 1;
  1506.         break;
  1507.  
  1508.           case 'm':
  1509.         if (force_reload)
  1510.           break;
  1511.         if (GET_CODE (operand) == MEM
  1512.             || (GET_CODE (operand) == REG
  1513.             && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1514.             && reg_renumber[REGNO (operand)] < 0))
  1515.           win = 1;
  1516.         if (GET_CODE (operand) == CONST_DOUBLE
  1517.             || CONSTANT_P (operand))
  1518.           badop = 0;
  1519.         break;
  1520.  
  1521.           case '<':
  1522.         if (GET_CODE (operand) == MEM
  1523.             && ! address_reloaded[i]
  1524.             && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
  1525.             || GET_CODE (XEXP (operand, 0)) == POST_DEC))
  1526.           win = 1;
  1527.         break;
  1528.  
  1529.           case '>':
  1530.         if (GET_CODE (operand) == MEM
  1531.             && ! address_reloaded[i]
  1532.             && (GET_CODE (XEXP (operand, 0)) == PRE_INC
  1533.             || GET_CODE (XEXP (operand, 0)) == POST_INC))
  1534.           win = 1;
  1535.         break;
  1536.  
  1537.         /* Memory operand whose address is offsettable.  */
  1538.           case 'o':
  1539.         if (force_reload)
  1540.           break;
  1541.         if ((GET_CODE (operand) == MEM
  1542.              && offsettable_memref_p (operand))
  1543.             /* Certain mem addresses will become offsettable
  1544.                after they themselves are reloaded.  This is important;
  1545.                we don't want our own handling of unoffsettables
  1546.                to override the handling of reg_equiv_address.  */
  1547.             || (GET_CODE (operand) == MEM
  1548.             && GET_CODE (XEXP (operand, 0)) == REG
  1549.             && (! ind_ok
  1550.                 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
  1551.             || (GET_CODE (operand) == REG
  1552.             && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1553.             && reg_renumber[REGNO (operand)] < 0))
  1554.           win = 1;
  1555.         if (GET_CODE (operand) == CONST_DOUBLE
  1556.             || CONSTANT_P (operand)
  1557.             || GET_CODE (operand) == MEM)
  1558.           badop = 0;
  1559.         offmemok = 1;
  1560.         break;
  1561.  
  1562.           case '&':
  1563.         /* Output operand that is stored before the need for the
  1564.            input operands (and their index registers) is over.  */
  1565.         if (GET_CODE (operand) == REG
  1566.             || GET_CODE (operand) == MEM)
  1567.           earlyclobber = 1, this_earlyclobber = 1;
  1568.         break;
  1569.  
  1570.           case 'F':
  1571.         if (GET_CODE (operand) == CONST_DOUBLE)
  1572.           win = 1;
  1573.         break;
  1574.  
  1575.           case 'G':
  1576.           case 'H':
  1577.         if (GET_CODE (operand) == CONST_DOUBLE
  1578.             && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
  1579.           win = 1;
  1580.         break;
  1581.  
  1582.           case 's':
  1583.         if (GET_CODE (operand) == CONST_INT)
  1584.           break;
  1585.           case 'i':
  1586.         if (CONSTANT_P (operand))
  1587.           win = 1;
  1588.         break;
  1589.  
  1590.           case 'n':
  1591.         if (GET_CODE (operand) == CONST_INT)
  1592.           win = 1;
  1593.         break;
  1594.  
  1595.           case 'I':
  1596.           case 'J':
  1597.           case 'K':
  1598.           case 'L':
  1599.           case 'M':
  1600.         if (GET_CODE (operand) == CONST_INT
  1601.             && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
  1602.           win = 1;
  1603.         break;
  1604.  
  1605.           case 'g':
  1606.         if (! force_reload
  1607.             && (GENERAL_REGS == ALL_REGS
  1608.             || GET_CODE (operand) != REG
  1609.             || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1610.                 && reg_renumber[REGNO (operand)] < 0)))
  1611.           win = 1;
  1612.         /* Drop through into 'r' case */
  1613.  
  1614.           case 'r':
  1615.         this_alternative[i]
  1616.           = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
  1617.         goto reg;
  1618.  
  1619.           default:
  1620.         this_alternative[i]
  1621.           = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
  1622.         
  1623.           reg:
  1624.         winreg = 1;
  1625.         if (GET_CODE (operand) == REG
  1626.             && reg_fits_class_p (operand, this_alternative[i],
  1627.                      offset, GET_MODE (recog_operand[i])))
  1628.           win = 1;
  1629.         break;
  1630.           }
  1631.  
  1632.       constraints[i] = p;
  1633.  
  1634.       /* If this operand could be handled with a reg,
  1635.          and some reg is allowed, then this operand can be handled.  */
  1636.       if (winreg && this_alternative[i] != (int) NO_REGS)
  1637.         badop = 0;
  1638.  
  1639.       /* Record which operands fit this alternative.  */
  1640.       this_alternative_earlyclobber[i] = earlyclobber;
  1641.       if (win && ! force_reload)
  1642.         this_alternative_win[i] = 1;
  1643.       else
  1644.         {
  1645.           this_alternative_offmemok[i] = offmemok;
  1646.           losers++;
  1647.           if (badop)
  1648.         bad = 1;
  1649.           /* Alternative loses if it has no regs for a reg operand.  */
  1650.           if (GET_CODE (operand) == REG
  1651.           && this_alternative[i] == (int) NO_REGS
  1652.           && this_alternative_matches[i] < 0)
  1653.         bad = 1;
  1654.         }
  1655.     }
  1656.  
  1657.       /* Now see if any output operands that are marked "earlyclobber"
  1658.      in this alternative conflict with any input operands
  1659.      or any memory addresses.  */
  1660.  
  1661.       for (i = 0; i < noperands; i++)
  1662.     if (this_alternative_earlyclobber[i]
  1663.         && this_alternative_win[i])
  1664.       {
  1665.         struct decomposition early_data; 
  1666.         int j;
  1667.  
  1668.         early_data = decompose (recog_operand[i]);
  1669.  
  1670.         for (j = 0; j < noperands; j++)
  1671.           /* Is this an input operand or a memory ref?  */
  1672.           if ((GET_CODE (recog_operand[j]) == MEM
  1673.            || modified[j] != RELOAD_WRITE)
  1674.           && j != i
  1675.           /* Don't count an input operand that is constrained to match
  1676.              the early clobber operand.  */
  1677.           && ! (this_alternative_matches[j] == i
  1678.             && rtx_equal_p (recog_operand[i], recog_operand[j]))
  1679.           /* Is it altered by storing the earlyclobber operand?  */
  1680.           && !immune_p (recog_operand[j], recog_operand[i], early_data))
  1681.         {
  1682.           /* If the output is in a single-reg class,
  1683.              it's costly to reload it, so reload the input instead.  */
  1684.           if (reg_class_size[this_alternative[i]] == 1
  1685.               && (GET_CODE (recog_operand[j]) == REG
  1686.               || GET_CODE (recog_operand[j]) == SUBREG))
  1687.             {
  1688.               losers++;
  1689.               this_alternative_win[j] = 0;
  1690.             }
  1691.           else
  1692.             break;
  1693.         }
  1694.         /* If an earlyclobber operand conflicts with something,
  1695.            it must be reloaded, so request this and count the cost.  */
  1696.         if (j != noperands)
  1697.           {
  1698.         losers++;
  1699.         this_alternative_win[i] = 0;
  1700.         for (j = 0; j < noperands; j++)
  1701.           if (this_alternative_matches[j] == i
  1702.               && this_alternative_win[j])
  1703.             {
  1704.               this_alternative_win[j] = 0;
  1705.               losers++;
  1706.             }
  1707.           }
  1708.       }
  1709.  
  1710.       /* If one alternative accepts all the operands, no reload required,
  1711.      choose that alternative; don't consider the remaining ones.  */
  1712.       if (losers == 0)
  1713.     {
  1714.       /* Unswap these so that they are never swapped at `finish'.  */
  1715.       if (commutative >= 0)
  1716.         {
  1717.           recog_operand[commutative] = substed_operand[commutative];
  1718.           recog_operand[commutative + 1]
  1719.         = substed_operand[commutative + 1];
  1720.         }
  1721.       for (i = 0; i < noperands; i++)
  1722.         {
  1723.           goal_alternative_win[i] = 1;
  1724.           goal_alternative[i] = this_alternative[i];
  1725.           goal_alternative_offmemok[i] = this_alternative_offmemok[i];
  1726.           goal_alternative_matches[i] = this_alternative_matches[i];
  1727.           goal_alternative_earlyclobber[i]
  1728.         = this_alternative_earlyclobber[i];
  1729.         }
  1730.       goal_alternative_number = this_alternative_number;
  1731.       goal_alternative_swapped = swapped;
  1732.       goal_earlyclobber = this_earlyclobber;
  1733.       goto finish;
  1734.     }
  1735.  
  1736.       /* REJECT, set by the ! and ? constraint characters,
  1737.      discourages the use of this alternative for a reload goal.  */
  1738.       if (reject > 0)
  1739.     losers += reject;
  1740.  
  1741.       /* If this alternative can be made to work by reloading,
  1742.      and it needs less reloading than the others checked so far,
  1743.      record it as the chosen goal for reloading.  */
  1744.       if (! bad && best > losers)
  1745.     {
  1746.       for (i = 0; i < noperands; i++)
  1747.         {
  1748.           goal_alternative[i] = this_alternative[i];
  1749.           goal_alternative_win[i] = this_alternative_win[i];
  1750.           goal_alternative_offmemok[i] = this_alternative_offmemok[i];
  1751.           goal_alternative_matches[i] = this_alternative_matches[i];
  1752.           goal_alternative_earlyclobber[i]
  1753.         = this_alternative_earlyclobber[i];
  1754.         }
  1755.       goal_alternative_swapped = swapped;
  1756.       best = losers;
  1757.       goal_alternative_number = this_alternative_number;
  1758.       goal_earlyclobber = this_earlyclobber;
  1759.     }
  1760.     }
  1761.  
  1762.   /* If insn is commutative (it's safe to exchange a certain pair of operands)
  1763.      then we need to try each alternative twice,
  1764.      the second time matching those two operands
  1765.      as if we had exchanged them.
  1766.      To do this, really exchange them in operands.
  1767.  
  1768.      If we have just tried the alternatives the second time,
  1769.      return operands to normal and drop through.  */
  1770.  
  1771.   if (commutative >= 0)
  1772.     {
  1773.       swapped = !swapped;
  1774.       if (swapped)
  1775.     {
  1776.       recog_operand[commutative] = substed_operand[commutative + 1];
  1777.       recog_operand[commutative + 1] = substed_operand[commutative];
  1778.  
  1779.       bcopy (constraints1, constraints, noperands * sizeof (char *));
  1780.       goto try_swapped;
  1781.     }
  1782.       else
  1783.     {
  1784.       recog_operand[commutative] = substed_operand[commutative];
  1785.       recog_operand[commutative + 1] = substed_operand[commutative + 1];
  1786.     }
  1787.     }
  1788.  
  1789.   /* The operands don't meet the constraints.
  1790.      goal_alternative describes the alternative
  1791.      that we could reach by reloading the fewest operands.
  1792.      Reload so as to fit it.  */
  1793.  
  1794.   if (best == MAX_RECOG_OPERANDS + 100)
  1795.     {
  1796.       /* No alternative works with reloads??  */
  1797.       if (insn_code_number >= 0)
  1798.     abort ();
  1799.       error_for_asm (insn, "inconsistent operand constraints in an `asm'");
  1800.       /* Avoid further trouble with this insn.  */
  1801.       PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
  1802.       n_reloads = 0;
  1803.       return;
  1804.     }
  1805.  
  1806.   /* Jump to `finish' from above if all operands are valid already.
  1807.      In that case, goal_alternative_win is all 1.  */
  1808.  finish:
  1809.  
  1810.   /* Right now, for any pair of operands I and J that are required to match,
  1811.      with I < J,
  1812.      goal_alternative_matches[J] is I.
  1813.      Set up goal_alternative_matched as the inverse function:
  1814.      goal_alternative_matched[I] = J.  */
  1815.  
  1816.   for (i = 0; i < noperands; i++)
  1817.     goal_alternative_matched[i] = -1;
  1818.  
  1819.   for (i = 0; i < noperands; i++)
  1820.     if (! goal_alternative_win[i]
  1821.     && goal_alternative_matches[i] >= 0)
  1822.       goal_alternative_matched[goal_alternative_matches[i]] = i;
  1823.  
  1824.   /* If the best alternative is with operands 1 and 2 swapped,
  1825.      consider them swapped before reporting the reloads.  */
  1826.  
  1827.   if (goal_alternative_swapped)
  1828.     {
  1829.       register rtx tem;
  1830.  
  1831.       tem = substed_operand[commutative];
  1832.       substed_operand[commutative] = substed_operand[commutative + 1];
  1833.       substed_operand[commutative + 1] = tem;
  1834.       tem = recog_operand[commutative];
  1835.       recog_operand[commutative] = recog_operand[commutative + 1];
  1836.       recog_operand[commutative + 1] = tem;
  1837.     }
  1838.  
  1839.   /* Perform whatever substitutions on the operands we are supposed
  1840.      to make due to commutativity or replacement of registers
  1841.      with equivalent constants or memory slots.  */
  1842.  
  1843.   for (i = 0; i < noperands; i++)
  1844.     {
  1845.       *recog_operand_loc[i] = substed_operand[i];
  1846.       /* While we are looping on operands, initialize this.  */
  1847.       operand_reloadnum[i] = -1;
  1848.     }
  1849.  
  1850.   /* Any constants that aren't allowed and can't be reloaded
  1851.      into memory locations are here changed into memory references.  */
  1852.   for (i = 0; i < noperands; i++)
  1853.     if (! goal_alternative_win[i]
  1854.     && (GET_CODE (recog_operand[i]) == CONST_DOUBLE
  1855.         || CONSTANT_P (recog_operand[i]))
  1856.     && (PREFERRED_RELOAD_CLASS (recog_operand[i],
  1857.                     (enum reg_class) goal_alternative[i])
  1858.         == NO_REGS))
  1859.       {
  1860.     enum machine_mode mode = operand_mode[i];
  1861.     *recog_operand_loc[i] = recog_operand[i]
  1862.       = (GET_CODE (recog_operand[i]) == CONST_DOUBLE
  1863.          ? force_const_double_mem (recog_operand[i])
  1864.          : force_const_mem (mode != VOIDmode ? mode : SImode,
  1865.                 recog_operand[i]));
  1866.     find_reloads_toplev (recog_operand[i]);
  1867.     if (alternative_allows_memconst (constraints1[i], goal_alternative_number))
  1868.       goal_alternative_win[i] = 1;
  1869.       }
  1870.  
  1871.   /* Now record reloads for all the operands that need them.  */
  1872.   for (i = 0; i < noperands; i++)
  1873.     if (! goal_alternative_win[i])
  1874.       {
  1875.     /* Operands that match previous ones have already been handled.  */
  1876.     if (goal_alternative_matches[i] >= 0)
  1877.       ;
  1878.     /* Handle an operand with a nonoffsettable address
  1879.        appearing where an offsettable address will do
  1880.        by reloading the address into a base register.  */
  1881.     else if (goal_alternative_matched[i] == -1
  1882.          && goal_alternative_offmemok[i]
  1883.          && GET_CODE (recog_operand[i]) == MEM)
  1884.       {
  1885.         operand_reloadnum[i]
  1886.           = push_reload (XEXP (recog_operand[i], 0), 0,
  1887.                  &XEXP (recog_operand[i], 0), 0,
  1888.                  BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
  1889.                  0, 0, 0, 0);
  1890.         reload_inc[operand_reloadnum[i]]
  1891.           = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
  1892.       }
  1893.     else if (goal_alternative_matched[i] == -1)
  1894.       operand_reloadnum[i] =
  1895.         push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1896.              modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1897.              recog_operand_loc[i], 0,
  1898.              (enum reg_class) goal_alternative[i],
  1899.              (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1900.              (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1901.              (insn_code_number < 0 ? 0
  1902.               : insn_operand_strict_low[insn_code_number][i]),
  1903.              0, 0);
  1904.     /* In a matching pair of operands, one must be input only
  1905.        and the other must be output only.
  1906.        Pass the input operand as IN and the other as OUT.  */
  1907.     else if (modified[i] == RELOAD_READ
  1908.          && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
  1909.       {
  1910.         operand_reloadnum[i]
  1911.           = push_reload (recog_operand[i],
  1912.                  recog_operand[goal_alternative_matched[i]],
  1913.                  recog_operand_loc[i],
  1914.                  recog_operand_loc[goal_alternative_matched[i]],
  1915.                  (enum reg_class) goal_alternative[i],
  1916.                  operand_mode[i],
  1917.                  operand_mode[goal_alternative_matched[i]],
  1918.                  VOIDmode, 0, 0);
  1919.         operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
  1920.       }
  1921.     else if (modified[i] == RELOAD_WRITE
  1922.          && modified[goal_alternative_matched[i]] == RELOAD_READ)
  1923.       {
  1924.         operand_reloadnum[goal_alternative_matched[i]]
  1925.           = push_reload (recog_operand[goal_alternative_matched[i]],
  1926.                  recog_operand[i],
  1927.                  recog_operand_loc[goal_alternative_matched[i]],
  1928.                  recog_operand_loc[i],
  1929.                  (enum reg_class) goal_alternative[i],
  1930.                  operand_mode[goal_alternative_matched[i]],
  1931.                  operand_mode[i],
  1932.                  VOIDmode, 0, 0);
  1933.         operand_reloadnum[i] = output_reloadnum;
  1934.       }
  1935.     else if (insn_code_number >= 0)
  1936.       abort ();
  1937.     else
  1938.       {
  1939.         error_for_asm (insn, "inconsistent operand constraints in an `asm'");
  1940.         /* Avoid further trouble with this insn.  */
  1941.         PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
  1942.         n_reloads = 0;
  1943.         return;
  1944.       }
  1945.       }
  1946.     else if (goal_alternative_matched[i] < 0
  1947.          && goal_alternative_matches[i] < 0
  1948.          && optimize)
  1949.       {
  1950.     rtx operand = recog_operand[i];
  1951.     /* For each non-matching operand that's a pseudo-register 
  1952.        that didn't get a hard register, make an optional reload.
  1953.        This may get done even if the insn needs no reloads otherwise.  */
  1954.     /* (It would be safe to make an optional reload for a matching pair
  1955.        of operands, but we don't bother yet.)  */
  1956.     while (GET_CODE (operand) == SUBREG)
  1957.       operand = XEXP (operand, 0);
  1958.     if (GET_CODE (operand) == REG
  1959.         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1960.         && reg_renumber[REGNO (operand)] < 0
  1961.         && (enum reg_class) goal_alternative[i] != NO_REGS
  1962.         /* Don't make optional output reloads for jump insns
  1963.            (such as aobjeq on the vax).  */
  1964.         && (modified[i] == RELOAD_READ
  1965.         || GET_CODE (insn) != JUMP_INSN))
  1966.       operand_reloadnum[i]
  1967.         = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1968.                modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1969.                recog_operand_loc[i], 0,
  1970.                (enum reg_class) goal_alternative[i],
  1971.                (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1972.                (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1973.                (insn_code_number < 0 ? 0
  1974.                 : insn_operand_strict_low[insn_code_number][i]),
  1975.                1, 0);
  1976.     /* Make an optional reload for an explicit mem ref.  */
  1977.     else if (GET_CODE (operand) == MEM
  1978.          && (enum reg_class) goal_alternative[i] != NO_REGS
  1979.          /* Don't make optional output reloads for jump insns
  1980.             (such as aobjeq on the vax).  */
  1981.          && (modified[i] == RELOAD_READ
  1982.              || GET_CODE (insn) != JUMP_INSN))
  1983.       operand_reloadnum[i]
  1984.         = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1985.                modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1986.                recog_operand_loc[i], 0,
  1987.                (enum reg_class) goal_alternative[i],
  1988.                (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1989.                (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1990.                (insn_code_number < 0 ? 0
  1991.                 : insn_operand_strict_low[insn_code_number][i]),
  1992.                1, 0);
  1993.       }
  1994.  
  1995.   /* Record the values of the earlyclobber operands for the caller.  */
  1996.   if (goal_earlyclobber)
  1997.     for (i = 0; i < noperands; i++)
  1998.       if (goal_alternative_earlyclobber[i])
  1999.     reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
  2000.  
  2001.   /* If this insn pattern contains any MATCH_DUP's, make sure that
  2002.      they will be substituted if the operands they match are substituted.
  2003.      Also do now any substitutions we already did on the operands.  */
  2004.   if (insn_code_number >= 0)
  2005.     for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
  2006.       {
  2007.     int opno = recog_dup_num[i];
  2008.     *recog_dup_loc[i] = *recog_operand_loc[opno];
  2009.     if (operand_reloadnum[opno] >= 0)
  2010.       push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
  2011.                 insn_operand_mode[insn_code_number][opno]);
  2012.       }
  2013.  
  2014. #if 0
  2015.   /* This loses because reloading of prior insns can invalidate the equivalence
  2016.      (or at least find_equiv_reg isn't smart enough to find it any more),
  2017.      causing this insn to need more reload regs than it needed before.
  2018.      It may be too late to make the reload regs available.
  2019.      Now this optimization is done safely in choose_reload_targets.  */
  2020.  
  2021.   /* For each reload of a reg into some other class of reg,
  2022.      search for an existing equivalent reg (same value now) in the right class.
  2023.      We can use it as long as we don't need to change its contents.  */
  2024.   for (i = 0; i < n_reloads; i++)
  2025.     if (reload_reg_rtx[i] == 0
  2026.     && reload_in[i] != 0
  2027.     && GET_CODE (reload_in[i]) == REG
  2028.     && reload_out[i] == 0)
  2029.       {
  2030.     reload_reg_rtx[i]
  2031.       = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
  2032.                 static_reload_reg_p, 0, reload_inmode[i]);
  2033.     /* Prevent generation of insn to load the value
  2034.        because the one we found already has the value.  */
  2035.     if (reload_reg_rtx[i])
  2036.       reload_in[i] = reload_reg_rtx[i];
  2037.       }
  2038. #endif
  2039.  
  2040. #else /* no REGISTER_CONSTRAINTS */
  2041.   int noperands;
  2042.   int insn_code_number;
  2043.   int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen.  */
  2044.   register int i;
  2045.   rtx body = PATTERN (insn);
  2046.  
  2047.   n_reloads = 0;
  2048.   n_replacements = 0;
  2049.   n_earlyclobbers = 0;
  2050.   replace_reloads = replace;
  2051.   indirect_ok = ind_ok;
  2052.   this_insn = insn;
  2053.  
  2054.   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
  2055.      Store the operand values in RECOG_OPERAND and the locations
  2056.      of the words in the insn that point to them in RECOG_OPERAND_LOC.
  2057.      Return if the insn needs no reload processing.  */
  2058.  
  2059.   switch (GET_CODE (body))
  2060.     {
  2061.     case USE:
  2062.     case CLOBBER:
  2063.     case ASM_INPUT:
  2064.     case ADDR_VEC:
  2065.     case ADDR_DIFF_VEC:
  2066.       return;
  2067.  
  2068.     case PARALLEL:
  2069.     case SET:
  2070.       noperands = asm_noperands (body);
  2071.       if (noperands >= 0)
  2072.     {
  2073.       /* This insn is an `asm' with operands.
  2074.          First, find out how many operands, and allocate space.  */
  2075.  
  2076.       insn_code_number = -1;
  2077.       /* ??? This is a bug! ???
  2078.          Give up and delete this insn if it has too many operands.  */
  2079.       if (noperands > MAX_RECOG_OPERANDS)
  2080.         abort ();
  2081.  
  2082.       /* Now get the operand values out of the insn.  */
  2083.  
  2084.       decode_asm_operands (body, recog_operand, recog_operand_loc, 0, 0);
  2085.       break;
  2086.     }
  2087.  
  2088.     default:
  2089.       /* Ordinary insn: recognize it, allocate space for operands and
  2090.      constraints, and get them out via insn_extract.  */
  2091.  
  2092.       insn_code_number = recog_memoized (insn);
  2093.       noperands = insn_n_operands[insn_code_number];
  2094.       insn_extract (insn);
  2095.     }
  2096.  
  2097.   if (noperands == 0)
  2098.     return;
  2099.  
  2100.   for (i = 0; i < noperands; i++)
  2101.     {
  2102.       register RTX_CODE code = GET_CODE (recog_operand[i]);
  2103.  
  2104.       if (insn_code_number >= 0)
  2105.     if (insn_operand_address_p[insn_code_number][i])
  2106.       find_reloads_address (VOIDmode, 0,
  2107.                 recog_operand[i], recog_operand_loc[i],
  2108.                 recog_operand[i]);
  2109.       if (code == MEM)
  2110.     find_reloads_address (GET_MODE (recog_operand[i]),
  2111.                   recog_operand_loc[i],
  2112.                   XEXP (recog_operand[i], 0),
  2113.                   &XEXP (recog_operand[i], 0),
  2114.                   recog_operand[i]);
  2115.       if (code == SUBREG)
  2116.     recog_operand[i] = *recog_operand_loc[i]
  2117.       = find_reloads_toplev (recog_operand[i]);
  2118.       if (code == REG)
  2119.     {
  2120.       register int regno = REGNO (recog_operand[i]);
  2121.       if (reg_equiv_constant[regno] != 0)
  2122.         recog_operand[i] = *recog_operand_loc[i]
  2123.           = reg_equiv_constant[regno];
  2124. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  2125.      that feeds this insn.  */
  2126.       if (reg_equiv_mem[regno] != 0)
  2127.         recog_operand[i] = *recog_operand_loc[i]
  2128.           = reg_equiv_mem[regno];
  2129. #endif
  2130.     }
  2131.     }
  2132. #endif /* no REGISTER_CONSTRAINTS */
  2133.  
  2134.   /* Determine which part of the insn each reload is needed for,
  2135.      based on which operand the reload is needed for.
  2136.      Reloads of entire operands are classified as RELOAD_OTHER.
  2137.      So are reloads for which a unique purpose is not known.  */
  2138.  
  2139.   for (i = 0; i < n_reloads; i++)
  2140.     {
  2141.       reload_when_needed[i] = RELOAD_OTHER;
  2142.  
  2143.       if (reload_needed_for[i] != 0 && ! reload_needed_for_multiple[i])
  2144.     {
  2145.       int j;
  2146.       int output_address = 0;
  2147.       int input_address = 0;
  2148.       int operand_address = 0;
  2149.  
  2150.       /* This reload is needed only for the address of something.
  2151.          Determine whether it is needed for addressing an operand
  2152.          being reloaded for input, whether it is needed for an
  2153.          operand being reloaded for output, and whether it is needed
  2154.          for addressing an operand that won't really be reloaded.  */
  2155.  
  2156.       for (j = 0; j < n_reloads; j++)
  2157.         if (reload_needed_for[i] == reload_in[j]
  2158.         || reload_needed_for[i] == reload_out[j])
  2159.           {
  2160.         if (reload_optional[j])
  2161.           operand_address = 1;
  2162.         else
  2163.           {
  2164.             if (reload_needed_for[i] == reload_in[j])
  2165.               input_address = 1;
  2166.             if (reload_needed_for[i] == reload_out[j])
  2167.               output_address = 1;
  2168.           }
  2169.           }
  2170.  
  2171.       /* If it is needed for only one of those, record which one.  */
  2172.  
  2173.       if (input_address && ! output_address && ! operand_address)
  2174.         reload_when_needed[i] = RELOAD_FOR_INPUT_RELOAD_ADDRESS;
  2175.       if (output_address && ! input_address && ! operand_address)
  2176.         reload_when_needed[i] = RELOAD_FOR_OUTPUT_RELOAD_ADDRESS;
  2177.       if (operand_address && ! input_address && ! output_address)
  2178.         reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
  2179.     }
  2180.     }
  2181.  
  2182.   /* Perhaps an output reload can be combined with another
  2183.      to reduce needs by one.  */
  2184.   if (!goal_earlyclobber)
  2185.     combine_reloads ();
  2186. }
  2187.  
  2188. /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
  2189.    accepts a memory operand with constant address.  */
  2190.  
  2191. static int
  2192. alternative_allows_memconst (constraint, altnum)
  2193.      char *constraint;
  2194.      int altnum;
  2195. {
  2196.   register int c;
  2197.   /* Skip alternatives before the one requested.  */
  2198.   while (altnum > 0)
  2199.     {
  2200.       while (*constraint++ != ',');
  2201.       altnum--;
  2202.     }
  2203.   /* Scan the requested alternative for 'm' or 'o'.
  2204.      If one of them is present, this alternative accepts memory constants.  */
  2205.   while ((c = *constraint++) && c != ',' && c != '#')
  2206.     if (c == 'm' || c == 'o')
  2207.       return 1;
  2208.   return 0;
  2209. }
  2210.  
  2211. /* Scan X for memory references and scan the addresses for reloading.
  2212.    Also checks for references to "constant" regs that we want to eliminate
  2213.    and replaces them with the values they stand for.
  2214.    We may alter X descructively if it contains a reference to such.
  2215.    If X is just a constant reg, we return the equivalent value
  2216.    instead of X.  */
  2217.  
  2218. static rtx
  2219. find_reloads_toplev (x)
  2220.      rtx x;
  2221. {
  2222.   register RTX_CODE code = GET_CODE (x);
  2223.  
  2224.   register char *fmt = GET_RTX_FORMAT (code);
  2225.   register int i;
  2226.  
  2227.   if (code == REG)
  2228.     {
  2229.       /* This code is duplicated for speed in find_reloads.  */
  2230.       register int regno = REGNO (x);
  2231.       if (reg_equiv_constant[regno] != 0)
  2232.     x = reg_equiv_constant[regno];
  2233. #if 0
  2234. /*  This creates (subreg (mem...)) which would cause an unnecessary
  2235.     reload of the mem.  */
  2236.       else if (reg_equiv_mem[regno] != 0)
  2237.     x = reg_equiv_mem[regno];
  2238. #endif
  2239.       else if (reg_equiv_address[regno] != 0)
  2240.     {
  2241.       x = gen_rtx (MEM, GET_MODE (x),
  2242.                reg_equiv_address[regno]);
  2243.       find_reloads_address (GET_MODE (x), 0,
  2244.                 XEXP (x, 0),
  2245.                 &XEXP (x, 0), x);
  2246.     }
  2247.       return x;
  2248.     }
  2249.   if (code == MEM)
  2250.     {
  2251.       rtx tem = x;
  2252.       find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0), x);
  2253.       return tem;
  2254.     }
  2255.  
  2256.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
  2257.     {
  2258.       /* Check for SUBREG containing a REG that's equivalent to a constant.  */
  2259.       register int regno = REGNO (SUBREG_REG (x));
  2260.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  2261.       && reg_equiv_constant[regno] != 0)
  2262.     {
  2263.       /* If the constant has a known value, truncate it right now.  */
  2264.       if (GET_CODE (reg_equiv_constant[regno]) == CONST_INT)
  2265.         {
  2266.           int size = GET_MODE_BITSIZE (GET_MODE (x));
  2267.           if (size < BITS_PER_WORD)
  2268.         return gen_rtx (CONST_INT, VOIDmode,
  2269.                 INTVAL (reg_equiv_constant[regno])
  2270.                 & ((1 << size) - 1));
  2271.           return reg_equiv_constant[regno];
  2272.         }
  2273.       /* If the constant is symbolic, allow it to be substituted normally.
  2274.          push_reload will strip the subreg later.  */
  2275.     }
  2276.       /* If the subreg contains a reg that will be converted to a mem,
  2277.      convert the subreg to a narrower memref now.
  2278.      Otherwise, we would get (subreg (mem ...) ...),
  2279.      which would force reload of the mem.  */
  2280.       else if (regno >= FIRST_PSEUDO_REGISTER && reg_equiv_address[regno] != 0)
  2281.     {
  2282.       int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2283.       rtx addr;
  2284. #ifdef BYTES_BIG_ENDIAN
  2285.       offset += (GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  2286.              - GET_MODE_SIZE (GET_MODE (x)));
  2287. #endif
  2288.       addr = plus_constant (reg_equiv_address[regno], offset);
  2289.       x = gen_rtx (MEM, GET_MODE (x), addr);
  2290.       find_reloads_address (GET_MODE (x), 0,
  2291.                 XEXP (x, 0),
  2292.                 &XEXP (x, 0), x);
  2293.     }
  2294.  
  2295.     }
  2296.  
  2297.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2298.     {
  2299.       if (fmt[i] == 'e')
  2300.     XEXP (x, i) = find_reloads_toplev (XEXP (x, i));
  2301.     }
  2302.   return x;
  2303. }
  2304.  
  2305. static rtx
  2306. make_memloc (ad, regno)
  2307.      rtx ad;
  2308.      int regno;
  2309. {
  2310.   register int i;
  2311.   rtx tem = reg_equiv_address[regno];
  2312.   for (i = 0; i < n_memlocs; i++)
  2313.     if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
  2314.       return memlocs[i];
  2315.   tem = gen_rtx (MEM, GET_MODE (ad), tem);
  2316.   memlocs[n_memlocs++] = tem;
  2317.   return tem;
  2318. }
  2319.  
  2320. /* Record all reloads needed for handling memory address AD
  2321.    which appears in *LOC in a memory reference to mode MODE
  2322.    which itself is found in location  *MEMREFLOC.
  2323.    Note that we take shortcuts assuming that no multi-reg machine mode
  2324.    occurs as part of an address.
  2325.  
  2326.    OPERAND is the operand of the insn within which this address appears.
  2327.  
  2328.    Value is nonzero if this address is reloaded or replaced as a whole.
  2329.    This is interesting to the caller if the address is an autoincrement.  */
  2330.  
  2331. static int
  2332. find_reloads_address (mode, memrefloc, ad, loc, operand)
  2333.      enum machine_mode mode;
  2334.      rtx *memrefloc;
  2335.      rtx ad;
  2336.      rtx *loc;
  2337.      rtx operand;
  2338. {
  2339.   register int regno;
  2340.   rtx tem;
  2341.  
  2342.   if (GET_CODE (ad) == REG)
  2343.     {
  2344.       regno = REGNO (ad);
  2345.  
  2346.       if (reg_equiv_constant[regno] != 0)
  2347.     {
  2348.       if (strict_memory_address_p (mode, reg_equiv_constant[regno]))
  2349.         {
  2350.           *loc = ad = reg_equiv_constant[regno];
  2351.           return 1;
  2352.         }
  2353.     }
  2354. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  2355.      that feeds this insn.  */
  2356.       if (reg_equiv_mem[regno] != 0)
  2357.     {
  2358.       if (strict_memory_address_p (mode, reg_equiv_mem[regno]))
  2359.         {
  2360.           *loc = ad = reg_equiv_mem[regno];
  2361.           return 1;
  2362.         }
  2363.     }
  2364. #endif
  2365.       if (reg_equiv_address[regno] != 0)
  2366.     {
  2367.       rtx tem = make_memloc (ad, regno);
  2368.       push_reload (XEXP (tem, 0), 0, &XEXP (tem, 0), 0,
  2369.                BASE_REG_CLASS,
  2370.                GET_MODE (XEXP (tem, 0)), 0, VOIDmode, 0,
  2371.                operand);
  2372.       push_reload (tem, 0, loc, 0, BASE_REG_CLASS,
  2373.                GET_MODE (ad), 0, VOIDmode, 0,
  2374.                operand);
  2375.       return 1;
  2376.     }
  2377.       if (! (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  2378.          ? indirect_ok
  2379.          : REGNO_OK_FOR_BASE_P (regno)))
  2380.     {
  2381.       push_reload (ad, 0, loc, 0, BASE_REG_CLASS,
  2382.                GET_MODE (ad), 0, VOIDmode, 0, operand);
  2383.       return 1;
  2384.     }
  2385.       return 0;
  2386.     }
  2387.  
  2388.   if (strict_memory_address_p (mode, ad))
  2389.     {
  2390.       /* The address appears valid, so reloads are not needed.
  2391.      But the address may contain an eliminable register.
  2392.      This can happen because a machine with indirect addressing
  2393.      may consider a pseudo register by itself a valid address even when
  2394.      it has failed to get a hard reg.
  2395.      So do a tree-walk to find and eliminate all such regs.  */
  2396.  
  2397.       /* But first quickly dispose of a common case.  */
  2398.       if (GET_CODE (ad) == PLUS
  2399.       && GET_CODE (XEXP (ad, 1)) == CONST_INT
  2400.       && GET_CODE (XEXP (ad, 0)) == REG
  2401.       && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
  2402.     return 0;
  2403.  
  2404.       subst_reg_equivs_changed = 0;
  2405.       *loc = subst_reg_equivs (ad);
  2406.  
  2407.       if (! subst_reg_equivs_changed)
  2408.     return 0;
  2409.  
  2410.       /* Check result for validity after substitution.  */
  2411.       if (strict_memory_address_p (mode, ad))
  2412.     return 0;
  2413.     }
  2414.  
  2415.   /* If we have address of a stack slot but it's not valid
  2416.      (displacement is too large), compute the sum in a register.  */
  2417.   if (GET_CODE (ad) == PLUS
  2418.       && (XEXP (ad, 0) == frame_pointer_rtx
  2419. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2420.       || XEXP (ad, 0) == arg_pointer_rtx
  2421. #endif
  2422.       )
  2423.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  2424.     {
  2425.       /* Unshare the MEM rtx so we can safely alter it.  */
  2426.       if (memrefloc)
  2427.     {
  2428.       rtx oldref = *memrefloc;
  2429.       *memrefloc = copy_rtx (*memrefloc);
  2430.       loc = &XEXP (*memrefloc, 0);
  2431.       if (operand == oldref)
  2432.         operand = *memrefloc;
  2433.     }
  2434.       if (double_reg_address_ok)
  2435.     {
  2436.       /* Unshare the sum as well.  */
  2437.       *loc = ad = copy_rtx (ad);
  2438.       /* Reload the displacement into an index reg.
  2439.          We assume the frame pointer or arg pointer is a base reg.  */
  2440.       push_reload (XEXP (ad, 1), 0, &XEXP (ad, 1), 0, INDEX_REG_CLASS, 
  2441.                GET_MODE (ad), VOIDmode, 0, 0, operand);
  2442.     }
  2443.       else
  2444.     {
  2445.       /* If the sum of two regs is not necessarily valid,
  2446.          reload the sum into a base reg.
  2447.          That will at least work.  */
  2448.       push_reload (ad, 0, loc, 0, BASE_REG_CLASS,
  2449.                GET_MODE (ad), VOIDmode, 0, 0, operand);
  2450.     }
  2451.       return 1;
  2452.     }
  2453.  
  2454.   /* See if address becomes valid when an eliminable register
  2455.      in a sum is replaced.  */
  2456.  
  2457.   tem = ad;
  2458.   if (GET_CODE (ad) == PLUS)
  2459.     tem = subst_indexed_address (ad);
  2460.   if (tem != ad && strict_memory_address_p (mode, tem))
  2461.     {
  2462.       /* Ok, we win that way.  Replace any additional eliminable
  2463.      registers.  */
  2464.  
  2465.       subst_reg_equivs_changed = 0;
  2466.       tem = subst_reg_equivs (tem);
  2467.  
  2468.       /* Make sure that didn't make the address invalid again.  */
  2469.  
  2470.       if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
  2471.     {
  2472.       *loc = tem;
  2473.       return 0;
  2474.     }
  2475.     }
  2476.  
  2477.   /* If constants aren't valid addresses, reload the constant address
  2478.      into a register.  */
  2479.   if (CONSTANT_ADDRESS_P (ad) && ! strict_memory_address_p (mode, ad))
  2480.     {
  2481.       push_reload (ad, 0, loc, 0,
  2482.            BASE_REG_CLASS,
  2483.            Pmode, 0, VOIDmode, 0, operand);
  2484.       return 1;
  2485.     }
  2486.  
  2487.   return find_reloads_address_1 (ad, 0, loc, operand);
  2488. }
  2489.  
  2490. /* Find all pseudo regs appearing in AD
  2491.    that are eliminable in favor of equivalent values
  2492.    and do not have hard regs; replace them by their equivalents.  */
  2493.  
  2494. static rtx
  2495. subst_reg_equivs (ad)
  2496.      rtx ad;
  2497. {
  2498.   register RTX_CODE code = GET_CODE (ad);
  2499.   register int i;
  2500.   register char *fmt;
  2501.  
  2502.   switch (code)
  2503.     {
  2504.     case CONST_INT:
  2505.     case CONST:
  2506.     case CONST_DOUBLE:
  2507.     case SYMBOL_REF:
  2508.     case LABEL_REF:
  2509.     case PC:
  2510.     case CC0:
  2511.       return ad;
  2512.  
  2513.     case REG:
  2514.       {
  2515.     register int regno = REGNO (ad);
  2516.  
  2517.     if (reg_equiv_constant[regno] != 0)
  2518.       {
  2519.         subst_reg_equivs_changed = 1;
  2520.         return reg_equiv_constant[regno];
  2521.       }
  2522.       }
  2523.       return ad;
  2524.  
  2525.     case PLUS:
  2526.       /* Quickly dispose of a common case.  */
  2527.       if (XEXP (ad, 0) == frame_pointer_rtx
  2528.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  2529.     return ad;
  2530.     }
  2531.  
  2532.   fmt = GET_RTX_FORMAT (code);
  2533.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2534.     if (fmt[i] == 'e')
  2535.       XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
  2536.   return ad;
  2537. }
  2538.  
  2539. /* If ADDR is a sum containing a pseudo register that should be
  2540.    replaced with a constant (from reg_equiv_constant),
  2541.    return the result of doing so, and also apply the associative
  2542.    law so that the result is more likely to be a valid address.
  2543.    (But it is not guaranteed to be one.)
  2544.  
  2545.    In all other cases, return ADDR.  */
  2546.  
  2547. static rtx
  2548. subst_indexed_address (addr)
  2549.      rtx addr;
  2550. {
  2551.   rtx const_part = 0;
  2552.   rtx var_part = 0;
  2553.   int regno;
  2554.  
  2555.   if (GET_CODE (addr) == PLUS)
  2556.     {
  2557.       if (CONSTANT_P (XEXP (addr, 0)))
  2558.     const_part = XEXP (addr, 0),
  2559.     var_part = XEXP (addr, 1);
  2560.       else if (CONSTANT_P (XEXP (addr, 1)))
  2561.     const_part = XEXP (addr, 1),
  2562.     var_part = XEXP (addr, 0);
  2563.       else
  2564.     var_part = addr;
  2565.  
  2566.       if (const_part && GET_CODE (const_part) == CONST)
  2567.     const_part = XEXP (const_part, 0);
  2568.  
  2569.       if (GET_CODE (var_part) == REG
  2570.       && (regno = REGNO (var_part)) >= FIRST_PSEUDO_REGISTER
  2571.       && reg_renumber[regno] < 0
  2572.       && reg_equiv_constant[regno] != 0)
  2573.     return (const_part
  2574.             ? gen_rtx (CONST, VOIDmode,
  2575.                gen_rtx (PLUS, Pmode, const_part,
  2576.                     reg_equiv_constant[regno]))
  2577.         : reg_equiv_constant[regno]);
  2578.  
  2579.       if (GET_CODE (var_part) != PLUS)
  2580.     return addr;
  2581.  
  2582.       if (GET_CODE (XEXP (var_part, 0)) == REG
  2583.       && (regno = REGNO (XEXP (var_part, 0))) >= FIRST_PSEUDO_REGISTER
  2584.       && reg_renumber[regno] < 0
  2585.       && reg_equiv_constant[regno] != 0)
  2586.     return gen_rtx (PLUS, Pmode, XEXP (var_part, 1),
  2587.             (const_part
  2588.              ? gen_rtx (CONST, VOIDmode,
  2589.                     gen_rtx (PLUS, Pmode, const_part,
  2590.                          reg_equiv_constant[regno]))
  2591.              : reg_equiv_constant[regno]));
  2592.  
  2593.       if (GET_CODE (XEXP (var_part, 1)) == REG
  2594.       && (regno = REGNO (XEXP (var_part, 1))) >= FIRST_PSEUDO_REGISTER
  2595.       && reg_renumber[regno] < 0
  2596.       && reg_equiv_constant[regno] != 0)
  2597.     return gen_rtx (PLUS, Pmode, XEXP (var_part, 0),
  2598.             (const_part
  2599.              ? gen_rtx (CONST, VOIDmode,
  2600.                     gen_rtx (PLUS, Pmode, const_part,
  2601.                          reg_equiv_constant[regno]))
  2602.              : reg_equiv_constant[regno]));
  2603.     }
  2604.   return addr;
  2605. }
  2606.  
  2607. /* Record the pseudo registers we must reload into hard registers
  2608.    in a subexpression of a would-be memory address, X.
  2609.    (This function is not called if the address we find is strictly valid.)
  2610.    CONTEXT = 1 means we are considering regs as index regs,
  2611.    = 0 means we are considering them as base regs.
  2612.  
  2613.    OPERAND is the operand of the insn within which this address appears.
  2614.  
  2615.    We return nonzero if X, as a whole, is reloaded or replaced.  */
  2616.  
  2617. /* Note that we take shortcuts assuming that no multi-reg machine mode
  2618.    occurs as part of an address.
  2619.    Also, this is not fully machine-customizable; it works for machines
  2620.    such as vaxes and 68000's and 32000's, but other possible machines
  2621.    could have addressing modes that this does not handle right.  */
  2622.  
  2623. static int
  2624. find_reloads_address_1 (x, context, loc, operand)
  2625.      rtx x;
  2626.      int context;
  2627.      rtx *loc;
  2628.      rtx operand;
  2629. {
  2630.   register RTX_CODE code = GET_CODE (x);
  2631.  
  2632.   if (code == PLUS)
  2633.     {
  2634.       register rtx op0 = XEXP (x, 0);
  2635.       register rtx op1 = XEXP (x, 1);
  2636.       register RTX_CODE code0 = GET_CODE (op0);
  2637.       register RTX_CODE code1 = GET_CODE (op1);
  2638.       if (code0 == MULT || code0 == SIGN_EXTEND || code1 == MEM)
  2639.     {
  2640.       find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2641.       find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2642.     }
  2643.       else if (code1 == MULT || code1 == SIGN_EXTEND || code0 == MEM)
  2644.     {
  2645.       find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2646.       find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand);
  2647.     }
  2648.       else if (code0 == CONST_INT || code0 == CONST
  2649.            || code0 == SYMBOL_REF || code0 == LABEL_REF)
  2650.     {
  2651.       find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2652.     }
  2653.       else if (code1 == CONST_INT || code1 == CONST
  2654.            || code1 == SYMBOL_REF || code1 == LABEL_REF)
  2655.     {
  2656.       find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2657.     }
  2658.       else if (code0 == REG && code1 == REG)
  2659.     {
  2660.       if (REG_OK_FOR_INDEX_P (op0)
  2661.           && REG_OK_FOR_BASE_P (op1))
  2662.         return 0;
  2663.       else if (REG_OK_FOR_INDEX_P (op1)
  2664.           && REG_OK_FOR_BASE_P (op0))
  2665.         return 0;
  2666.       else if (REG_OK_FOR_BASE_P (op1))
  2667.         find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2668.       else if (REG_OK_FOR_BASE_P (op0))
  2669.         find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand);
  2670.       else if (REG_OK_FOR_INDEX_P (op1))
  2671.         find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2672.       else if (REG_OK_FOR_INDEX_P (op0))
  2673.         find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2674.       else
  2675.         {
  2676.           find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2677.           find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2678.         }
  2679.     }
  2680.       else if (code0 == REG)
  2681.     {
  2682.       find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2683.       find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2684.     }
  2685.       else if (code1 == REG)
  2686.     {
  2687.       find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand);
  2688.       find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2689.     }
  2690.     }
  2691.   else if (code == POST_INC || code == POST_DEC
  2692.        || code == PRE_INC || code == PRE_DEC)
  2693.     {
  2694.       if (GET_CODE (XEXP (x, 0)) == REG)
  2695.     {
  2696.       register int regno = REGNO (XEXP (x, 0));
  2697.       int value = 0;
  2698.  
  2699.       /* A register that is incremented cannot be constant!  */
  2700.       if (regno >= FIRST_PSEUDO_REGISTER
  2701.           && reg_equiv_constant[regno] != 0)
  2702.         abort ();
  2703.  
  2704.       /* Handle a register that is equivalent to a memory location
  2705.          which cannot be addressed directly.  */
  2706.       if (reg_equiv_address[regno] != 0)
  2707.         {
  2708.           rtx tem = make_memloc (XEXP (x, 0), regno);
  2709.           /* First reload the memory location's address.  */
  2710.           push_reload (XEXP (tem, 0), 0, &XEXP (tem, 0), 0,
  2711.                BASE_REG_CLASS,
  2712.                GET_MODE (XEXP (tem, 0)), 0, VOIDmode, 0,
  2713.                operand);
  2714.           /* Put this inside a new increment-expression.  */
  2715.           x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
  2716.           /* Proceed to reload that, as if it contained a register.  */
  2717.         }
  2718.  
  2719.       /* If we have a hard register that is ok as an index,
  2720.          don't make a reload.  If an autoincrement of a nice register
  2721.          isn't "valid", it must be that no autoincrement is "valid".
  2722.          If that is true and something made an autoincrement anyway,
  2723.          this must be a special context where one is allowed.
  2724.          (For example, a "push" instruction.)
  2725.          We can't improve this address, so leave it alone.  */
  2726.  
  2727.       /* Otherwise, reload the autoincrement into a suitable hard reg
  2728.          and record how much to increment by.  */
  2729.  
  2730.       if (reg_renumber[regno] >= 0)
  2731.         regno = reg_renumber[regno];
  2732.       if ((regno >= FIRST_PSEUDO_REGISTER
  2733.            || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  2734.             : REGNO_OK_FOR_BASE_P (regno))))
  2735.         {
  2736.           register rtx link;
  2737.  
  2738.           int reloadnum
  2739.         = push_reload (x, 0, loc, 0,
  2740.                    context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2741.                    GET_MODE (x), GET_MODE (x), VOIDmode, 0, operand);
  2742.           reload_inc[reloadnum]
  2743.         = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
  2744.  
  2745.           value = 1;
  2746.  
  2747.           /* Update the REG_INC notes.  */
  2748.  
  2749.           for (link = REG_NOTES (this_insn);
  2750.            link; link = XEXP (link, 1))
  2751.         if (REG_NOTE_KIND (link) == REG_INC
  2752.             && REGNO (XEXP (link, 0)) == REGNO (XEXP (x, 0)))
  2753.           push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
  2754.         }
  2755.       return value;
  2756.     }
  2757.     }
  2758.   else if (code == REG)
  2759.     {
  2760.       register int regno = REGNO (x);
  2761.  
  2762.       if (reg_equiv_constant[regno] != 0)
  2763.     {
  2764.       push_reload (reg_equiv_constant[regno], 0, loc, 0,
  2765.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2766.                GET_MODE (x), 0, VOIDmode, 0, operand);
  2767.       return 1;
  2768.     }
  2769.  
  2770. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  2771.      that feeds this insn.  */
  2772.       if (reg_equiv_mem[regno] != 0)
  2773.     {
  2774.       push_reload (reg_equiv_mem[regno], 0, loc, 0,
  2775.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2776.                GET_MODE (x), 0, VOIDmode, 0, operand);
  2777.       return 1;
  2778.     }
  2779. #endif
  2780.       if (reg_equiv_address[regno] != 0)
  2781.     {
  2782.       x = make_memloc (x, regno);
  2783.       push_reload (XEXP (x, 0), 0, &XEXP (x, 0), 0,
  2784.                BASE_REG_CLASS,
  2785.                GET_MODE (XEXP (x, 0)), 0, VOIDmode, 0, operand);
  2786.     }
  2787.  
  2788.       if (reg_renumber[regno] >= 0)
  2789.     regno = reg_renumber[regno];
  2790.       if ((regno >= FIRST_PSEUDO_REGISTER
  2791.        || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  2792.         : REGNO_OK_FOR_BASE_P (regno))))
  2793.     {
  2794.       push_reload (x, 0, loc, 0,
  2795.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2796.                GET_MODE (x), 0, VOIDmode, 0, operand);
  2797.       return 1;
  2798.     }
  2799.     }
  2800.   else
  2801.     {
  2802.       register char *fmt = GET_RTX_FORMAT (code);
  2803.       register int i;
  2804.       for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2805.     {
  2806.       if (fmt[i] == 'e')
  2807.         find_reloads_address_1 (XEXP (x, i), context, &XEXP (x, i), operand);
  2808.     }
  2809.     }
  2810.  
  2811.   return 0;
  2812. }
  2813.  
  2814. /* Substitute into X the registers into which we have reloaded
  2815.    the things that need reloading.  The array `replacements'
  2816.    says contains the locations of all pointers that must be changed
  2817.    and says what to replace them with.
  2818.  
  2819.    Return the rtx that X translates into; usually X, but modified.  */
  2820.  
  2821. void
  2822. subst_reloads ()
  2823. {
  2824.   register int i;
  2825.  
  2826.   for (i = 0; i < n_replacements; i++)
  2827.     {
  2828.       register struct replacement *r = &replacements[i];
  2829.       register rtx reloadreg = reload_reg_rtx[r->what];
  2830.       if (reloadreg)
  2831.     {
  2832.       /* Encapsulate RELOADREG so its machine mode matches what
  2833.          used to be there.  */
  2834.       if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
  2835.         reloadreg = gen_rtx (SUBREG, r->mode, reloadreg, 0);
  2836.       *r->where = reloadreg;
  2837.     }
  2838.       /* If reload got no reg and isn't optional, something's wrong.  */
  2839.       else if (! reload_optional[r->what])
  2840.     abort ();
  2841.     }
  2842. }
  2843.  
  2844. #if 0
  2845.  
  2846. /* [[This function is currently obsolete, now that volatility
  2847.    is represented by a special bit `volatil' so VOLATILE is never used;
  2848.    and UNCHANGING has never been brought into use.]]
  2849.  
  2850.    Alter X by eliminating all VOLATILE and UNCHANGING expressions.
  2851.    Each of them is replaced by its operand.
  2852.    Thus, (PLUS (VOLATILE (MEM (REG 5))) (CONST_INT 4))
  2853.    becomes (PLUS (MEM (REG 5)) (CONST_INT 4)).
  2854.  
  2855.    If X is itself a VOLATILE expression,
  2856.    we return the expression that should replace it
  2857.    but we do not modify X.  */
  2858.  
  2859. static rtx
  2860. forget_volatility (x)
  2861.      register rtx x;
  2862. {
  2863.   enum rtx_code code = GET_CODE (x);
  2864.   register char *fmt;
  2865.   register int i;
  2866.   register rtx value = 0;
  2867.  
  2868.   switch (code)
  2869.     {
  2870.     case LABEL_REF:
  2871.     case SYMBOL_REF:
  2872.     case CONST_INT:
  2873.     case CONST_DOUBLE:
  2874.     case CONST:
  2875.     case REG:
  2876.     case CC0:
  2877.     case PC:
  2878.       return x;
  2879.  
  2880.     case VOLATILE:
  2881.     case UNCHANGING:
  2882.       return XEXP (x, 0);
  2883.     }
  2884.  
  2885.   fmt = GET_RTX_FORMAT (code);
  2886.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2887.     {
  2888.       if (fmt[i] == 'e')
  2889.     XEXP (x, i) = forget_volatility (XEXP (x, i));
  2890.       if (fmt[i] == 'E')
  2891.     {
  2892.       register int j;
  2893.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2894.         XVECEXP (x, i, j) = forget_volatility (XVECEXP (x, i, j));
  2895.     }
  2896.     }
  2897.  
  2898.   return x;
  2899. }
  2900.  
  2901. #endif
  2902.  
  2903. /* Check the insns before INSN to see if there is a suitable register
  2904.    containing the same value as GOAL.
  2905.    If OTHER is -1, look for a register in class CLASS.
  2906.    Otherwise, just see if register number OTHER shares GOAL's value.
  2907.  
  2908.    Return an rtx for the register found, or zero if none is found.
  2909.  
  2910.    If RELOAD_REG_P is (short *)1,
  2911.    we reject any hard reg that appears in reload_reg_rtx
  2912.    because such a hard reg is also needed coming into this insn.
  2913.  
  2914.    If RELOAD_REG_P is any other nonzero value,
  2915.    it is a vector indexed by hard reg number
  2916.    and we reject any hard reg whose element in the vector is nonnegative
  2917.    as well as any that appears in reload_reg_rtx.
  2918.  
  2919.    If GOAL is zero, then GOALREG is a register number; we look
  2920.    for an equivalent for that register.
  2921.  
  2922.    MODE is the machine mode of the value we want an equivalence for.
  2923.    If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
  2924.  
  2925.    This function is used by jump.c as well as in the reload pass.
  2926.  
  2927.    If GOAL is a PLUS, we assume it adds the stack pointer to a constant.  */
  2928.  
  2929. rtx
  2930. find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
  2931.      register rtx goal;
  2932.      rtx insn;
  2933.      enum reg_class class;
  2934.      register int other;
  2935.      short *reload_reg_p;
  2936.      int goalreg;
  2937.      enum machine_mode mode;
  2938. {
  2939.   register rtx p = insn;
  2940.   rtx valtry, value, where;
  2941.   register rtx pat;
  2942.   register int regno = -1;
  2943.   int valueno;
  2944.   int goal_mem = 0;
  2945.   int goal_const = 0;
  2946.   int goal_mem_addr_varies = 0;
  2947.   int nregs;
  2948.   int valuenregs;
  2949.  
  2950.   if (goal == 0)
  2951.     regno = goalreg;
  2952.   else if (GET_CODE (goal) == REG)
  2953.     regno = REGNO (goal);
  2954.   else if (GET_CODE (goal) == MEM)
  2955.     {
  2956.       enum rtx_code code = GET_CODE (XEXP (goal, 0));
  2957.       if (MEM_VOLATILE_P (goal))
  2958.     return 0;
  2959.       if (flag_float_store
  2960.       && (GET_MODE (goal) == DFmode || GET_MODE (goal) == SFmode))
  2961.     return 0;
  2962.       /* An address with side effects must be reexecuted.  */
  2963.       switch (code)
  2964.     {
  2965.     case POST_INC:
  2966.     case PRE_INC:
  2967.     case POST_DEC:
  2968.     case PRE_DEC:
  2969.       return 0;
  2970.     }
  2971.       goal_mem = 1;
  2972.     }
  2973.   else if (CONSTANT_P (goal))
  2974.     goal_const = 1;
  2975.   else
  2976.     return 0;
  2977.  
  2978.   /* On some machines, certain regs must always be rejected
  2979.      because they don't behave the way ordinary registers do.  */
  2980.   
  2981. #ifdef OVERLAPPING_REGNO_P
  2982.    if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
  2983.        && OVERLAPPING_REGNO_P (regno))
  2984.      return 0;
  2985. #endif      
  2986.  
  2987.   /* Scan insns back from INSN, looking for one that copies
  2988.      a value into or out of GOAL.
  2989.      Stop and give up if we reach a label.  */
  2990.  
  2991.   while (1)
  2992.     {
  2993.       p = PREV_INSN (p);
  2994.       if (p == 0 || GET_CODE (p) == CODE_LABEL)
  2995.     return 0;
  2996.       if (GET_CODE (p) == INSN
  2997.       /* If we don't want spill regs (true for all calls in this file) */
  2998.       && (! (reload_reg_p != 0 && reload_reg_p != (short *)1)
  2999.       /* then ignore insns introduced by reload; they aren't useful
  3000.          and can cause results in reload_as_needed to be different
  3001.          from what they were when calculating the need for spills.
  3002.          If we notice an input-reload insn here, we will reject it below,
  3003.          but it might hide a usable equivalent.  That makes bad code.
  3004.          It may even abort: perhaps no reg was spilled for this insn
  3005.          because it was assumed we would find that equivalent.  */
  3006.           || INSN_UID (p) < reload_first_uid))
  3007.     {
  3008.       pat = PATTERN (p);
  3009.       /* First check for something that sets some reg equal to GOAL.  */
  3010.       if (GET_CODE (pat) == SET
  3011.           && ((regno >= 0
  3012.            && GET_CODE (SET_SRC (pat)) == REG
  3013.            && REGNO (SET_SRC (pat)) == regno
  3014.            && GET_CODE (valtry = SET_DEST (pat)) == REG)
  3015.           ||
  3016.           (regno >= 0
  3017.            && GET_CODE (SET_DEST (pat)) == REG
  3018.            && REGNO (SET_DEST (pat)) == regno
  3019.            && GET_CODE (valtry = SET_SRC (pat)) == REG)
  3020.           ||
  3021.           (goal_const && rtx_equal_p (SET_SRC (pat), goal)
  3022.            && GET_CODE (valtry = SET_DEST (pat)) == REG)
  3023.           || (goal_mem
  3024.               && GET_CODE (valtry = SET_DEST (pat)) == REG
  3025.               && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
  3026.           || (goal_mem
  3027.               && GET_CODE (valtry = SET_SRC (pat)) == REG
  3028.               && rtx_renumbered_equal_p (goal, SET_DEST (pat)))))
  3029.         if (valueno = REGNO (valtry),
  3030.         other >= 0
  3031.         ? valueno == other
  3032.         : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
  3033.            && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  3034.                      valueno)))
  3035.           {
  3036.         value = valtry;
  3037.         where = p;
  3038.         break;
  3039.           }
  3040.     }
  3041.     }
  3042.  
  3043.   /* We found a previous insn copying GOAL into a suitable other reg VALUE
  3044.      (or copying VALUE into GOAL, if GOAL is also a register).
  3045.      Now verify that VALUE is really valid.  */
  3046.  
  3047.   /* VALUENO is the register number of VALUE; a hard register.  */
  3048.  
  3049.   /* Don't find the sp as an equiv, since pushes that we don't notice
  3050.      would invalidate it.  */
  3051.   if (valueno == STACK_POINTER_REGNUM)
  3052.     return 0;
  3053.  
  3054.   /* Reject VALUE if the copy-insn moved the wrong sort of datum.  */
  3055.   if (GET_MODE (value) != mode)
  3056.     return 0;
  3057.  
  3058.   /* Reject VALUE if it was loaded from GOAL
  3059.      and is also a register that appears in the address of GOAL.  */
  3060.  
  3061.   if (goal_mem && value == SET_DEST (PATTERN (where))
  3062.       && refers_to_regno_p (valueno,
  3063.                 valueno + HARD_REGNO_NREGS (valueno, mode),
  3064.                 goal, 0))
  3065.     return 0;
  3066.  
  3067.   /* Reject VALUE if it is one of the regs reserved for reloads.
  3068.      Reload1 knows how to reuse them anyway, and it would get
  3069.      confused if we allocated one without its knowledge.
  3070.      (Now that insns introduced by reload are ignored above,
  3071.      this case shouldn't happen, but I'm not positive.)  */
  3072.  
  3073.   if (reload_reg_p != 0 && reload_reg_p != (short *)1
  3074.       && reload_reg_p[valueno] >= 0)
  3075.     return 0;
  3076.  
  3077.   /* On some machines, certain regs must always be rejected
  3078.      because they don't behave the way ordinary registers do.  */
  3079.   
  3080. #ifdef OVERLAPPING_REGNO_P
  3081.   if (OVERLAPPING_REGNO_P (valueno))
  3082.     return 0;
  3083. #endif      
  3084.  
  3085.   nregs = HARD_REGNO_NREGS (regno, mode);
  3086.   valuenregs = HARD_REGNO_NREGS (valueno, mode);
  3087.  
  3088.   /* Reject VALUE if it is a register being used for an input reload
  3089.      even if it is not one of those reserved.  */
  3090.  
  3091.   if (reload_reg_p != 0)
  3092.     {
  3093.       int i;
  3094.       for (i = 0; i < n_reloads; i++)
  3095.     if (reload_reg_rtx[i] != 0 && reload_in[i])
  3096.       {
  3097.         int regno1 = REGNO (reload_reg_rtx[i]);
  3098.         int nregs1 = HARD_REGNO_NREGS (regno1,
  3099.                        GET_MODE (reload_reg_rtx[i]));
  3100.         if (regno1 < valueno + valuenregs
  3101.         && regno1 + nregs1 > valueno)
  3102.           return 0;
  3103.       }
  3104.     }
  3105.  
  3106.   if (goal_mem)
  3107.     goal_mem_addr_varies = rtx_addr_varies_p (goal);
  3108.  
  3109.   /* Now verify that the values of GOAL and VALUE remain unaltered
  3110.      until INSN is reached.  */
  3111.  
  3112.   p = insn;
  3113.   while (1)
  3114.     {
  3115.       p = PREV_INSN (p);
  3116.       if (p == where)
  3117.     return value;
  3118.  
  3119.       /* Don't trust the conversion past a function call
  3120.      if either of the two is in a call-clobbered register, or memory.  */
  3121.       if (GET_CODE (p) == CALL_INSN
  3122.       && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
  3123.            && call_used_regs[regno])
  3124.           ||
  3125.           (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
  3126.            && call_used_regs[valueno])
  3127.           ||
  3128.           goal_mem))
  3129.     return 0;
  3130.  
  3131.       if (GET_CODE (p) == INSN || GET_CODE (p) == JUMP_INSN
  3132.       || GET_CODE (p) == CALL_INSN)
  3133.     {
  3134.       /* If this insn P stores in either GOAL or VALUE, return 0.
  3135.          If GOAL is a memory ref and this insn writes memory, return 0.
  3136.          If GOAL is a memory ref and its address is not constant,
  3137.          and this insn P changes a register, return 0.
  3138.          That is in lieue of checking whether GOAL uses this register.  */
  3139.  
  3140.       pat = PATTERN (p);
  3141.       if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
  3142.         {
  3143.           register rtx dest = SET_DEST (pat);
  3144.           while (GET_CODE (dest) == SUBREG
  3145.              || GET_CODE (dest) == ZERO_EXTRACT
  3146.              || GET_CODE (dest) == SIGN_EXTRACT
  3147.              || GET_CODE (dest) == STRICT_LOW_PART)
  3148.         dest = XEXP (dest, 0);
  3149.           if (GET_CODE (dest) == REG)
  3150.         {
  3151.           register int xregno = REGNO (dest);
  3152.           int xnregs;
  3153.           if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
  3154.             xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
  3155.           else
  3156.             xnregs = 1;
  3157.           if (xregno < regno + nregs && xregno + xnregs > regno)
  3158.             return 0;
  3159.           if (xregno < valueno + valuenregs
  3160.               && xregno + xnregs > valueno)
  3161.             return 0;
  3162.           if (goal_mem_addr_varies)
  3163.             return 0;
  3164.         }
  3165.           else if (goal_mem && GET_CODE (dest) == MEM
  3166.                && ! push_operand (dest, GET_MODE (dest)))
  3167.         return 0;
  3168.         }
  3169.       else if (GET_CODE (pat) == PARALLEL)
  3170.         {
  3171.           register int i;
  3172.           for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
  3173.         {
  3174.           register rtx v1 = XVECEXP (pat, 0, i);
  3175.           if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
  3176.             {
  3177.               register rtx dest = SET_DEST (v1);
  3178.               while (GET_CODE (dest) == SUBREG
  3179.                  || GET_CODE (dest) == ZERO_EXTRACT
  3180.                  || GET_CODE (dest) == SIGN_EXTRACT
  3181.                  || GET_CODE (dest) == STRICT_LOW_PART)
  3182.             dest = XEXP (dest, 0);
  3183.               if (GET_CODE (dest) == REG)
  3184.             {
  3185.               register int xregno = REGNO (dest);
  3186.               int xnregs;
  3187.               if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
  3188.                 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
  3189.               else
  3190.                 xnregs = 1;
  3191.               if (xregno < regno + nregs
  3192.                   && xregno + xnregs > regno)
  3193.                 return 0;
  3194.               if (xregno < valueno + valuenregs
  3195.                   && xregno + xnregs > valueno)
  3196.                 return 0;
  3197.               if (goal_mem_addr_varies)
  3198.                 return 0;
  3199.             }
  3200.               else if (goal_mem && GET_CODE (dest) == MEM
  3201.                    && ! push_operand (dest, GET_MODE (dest)))
  3202.             return 0;
  3203.             }
  3204.         }
  3205.         }
  3206.       /* If this insn auto-increments or auto-decrements
  3207.          either regno or valueno, return 0 now.
  3208.          If GOAL is a memory ref and its address is not constant,
  3209.          and this insn P increments a register, return 0.
  3210.          That is in lieue of checking whether GOAL uses this register.  */
  3211.       {
  3212.         register rtx link;
  3213.  
  3214.         for (link = REG_NOTES (p); link; link = XEXP (link, 1))
  3215.           if (REG_NOTE_KIND (link) == REG_INC)
  3216.         {
  3217.           register int incno = REGNO (XEXP (link, 0));
  3218.           if (incno < regno + nregs && incno >= regno)
  3219.             return 0;
  3220.           if (incno < valueno + valuenregs && incno >= valueno)
  3221.             return 0;
  3222.           if (goal_mem_addr_varies)
  3223.             return 0;
  3224.         }
  3225.       }
  3226.     }
  3227.     }
  3228. }
  3229.  
  3230. /* Find a place where INCED appears in an increment or decrement operator
  3231.    within X, and return the amount INCED is incremented or decremented by.
  3232.    The value is always positive.  */
  3233.  
  3234. static int
  3235. find_inc_amount (x, inced)
  3236.      rtx x, inced;
  3237. {
  3238.   register enum rtx_code code = GET_CODE (x);
  3239.   register char *fmt;
  3240.   register int i;
  3241.  
  3242.   if (code == MEM)
  3243.     {
  3244.       register rtx addr = XEXP (x, 0);
  3245.       if ((GET_CODE (addr) == PRE_DEC
  3246.        || GET_CODE (addr) == POST_DEC
  3247.        || GET_CODE (addr) == PRE_INC
  3248.        || GET_CODE (addr) == POST_INC)
  3249.       && XEXP (addr, 0) == inced)
  3250.     return GET_MODE_SIZE (GET_MODE (x));
  3251.     }
  3252.  
  3253.   fmt = GET_RTX_FORMAT (code);
  3254.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3255.     {
  3256.       if (fmt[i] == 'e')
  3257.     {
  3258.       register int tem = find_inc_amount (XEXP (x, i), inced);
  3259.       if (tem != 0)
  3260.         return tem;
  3261.     }
  3262.       if (fmt[i] == 'E')
  3263.     {
  3264.       register int j;
  3265.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  3266.         {
  3267.           register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
  3268.           if (tem != 0)
  3269.         return tem;
  3270.         }
  3271.     }
  3272.     }
  3273.  
  3274.   return 0;
  3275. }
  3276.